Hi, 2013/1/8 tamouse mailing lists <[email protected]>: > On Mon, Jan 7, 2013 at 12:01 AM, Matma Rex <[email protected]> wrote: >> On Mon, 07 Jan 2013 05:26:43 +0100, tamouse mailing lists >> <[email protected]> wrote: >> >>> On Sun, Jan 6, 2013 at 9:09 PM, windwiny <[email protected]> wrote: >>>> >>>> vs = (1..9).to_a >>>> => [1, 2, 3, 4, 5, 6, 7, 8, 9] >>>> >>>> v1 = vs.select { |n| if n==3..n==6 then 1 end } >>> >>> >>> What do you expect n==3..n==6 to do? That evaluates to a range of >>> booleans, depending on the value of n: >> >> >> These are so-called flip-flops, and a valid though obscure feature of Ruby. >> Here's a nicer test case: >> >> irb(main):001:0> (1..100).each do |i| >> irb(main):002:1* puts i if i==42..i==45 >> irb(main):003:1> end >> 42 >> 43 >> 44 >> 45 >> > > I really do not understand how this works. I can see what it produces, but > why? > You can see a detailed explanation at http://ruby.about.com/od/convolutedconstructions/ss/The-Curious-Case-Of-The-Flip-Flop.htm
Regards, Park Heesob -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
