[ruby-core:32697] Re: [Ruby 1.9-Feature#3845][Open] "in" infix operator

From: Yusuke ENDOH <mame@...>
Date: 2010-10-05 14:32:55 UTC
List: ruby-core #32697
Hi,

2010/9/29 Roger Pack <rogerdpack2@gmail.com>:
> I like it. =A0There's a kind of elegance in it
>
> if a in [1,2,3]
> =A0 =A0p ' it is in 1,2,3'
> end
>
> It works well with my head. =A0+1


Thanks, but it is a bit different from my original suggestion.
My suggestion does not require brackets:

  if a in 1,2,3
    p 'it is in 1,2,3'
  end

a in [1,2,3] is slightly verbose (for me) and inefficient because
it creates new array object when evaluated.
If you want to write array there, you can use splat operator:

  ary =3D [1,2,3]
  if a in *ary
    p 'it is in ary'
  end

--=20
Yusuke Endoh <mame@tsg.ne.jp>

In This Thread