From: windwiny Date: 2013-01-07T17:03:30+09:00 Subject: Re: ruby 1.9.3p362 ranges as conditions bug? --f46d042f95f0e2452b04d2ae29f8 Content-Type: text/plain; charset=UTF-8 Run code on irb, pry has different result, write code to file, run from file, that return same result. Maybe it is (1.9.3p362)irb's bug. 2013/1/7 Matma Rex > On Mon, 07 Jan 2013 05:26:43 +0100, tamouse mailing lists < > tamouse.lists@gmail.com> wrote: > > On Sun, Jan 6, 2013 at 9:09 PM, windwiny 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 > > windwiny, I wasn't able to replicate your results on ruby 1.9.3p0 > (2011-10-30) [i386-mingw32]. v1 and v3 both gave the same (first) result. > > --f46d042f95f0e2452b04d2ae29f8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Run code on irb, pry has different result, write code to file, run from fil= e, that return same result. Maybe it is=C2=A0(1.9.3p362)irb's bug.=C2= =A0

2013/1/7 Matma Rex = <matma.rex@gmai= l.com>
On Mon, 07 Jan 2013 05:26:= 43 +0100, tamouse mailing lists <tamouse.lists@gmail.com> wrote:

On Sun, Jan 6, 2013 at 9:09 PM, windwiny <windwiny.ubt@gmail.com> wrote:
vs =3D (1..9).to_a
=3D> [1, 2, 3, 4, 5, 6, 7, 8, 9]

v1 =3D vs.select { |n| if n=3D=3D3..n=3D=3D6 then 1 end }

What do you expect n=3D=3D3..n=3D=3D6 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* =C2=A0 puts i if i=3D=3D42..i=3D=3D45
irb(main):003:1> end
42
43
44
45

windwiny, I wasn't able to replicate your results on ruby 1.9.3p0 (2011= -10-30) [i386-mingw32]. v1 and v3 both gave the same (first) result.


--f46d042f95f0e2452b04d2ae29f8--