From: Etienne Vallette d'Osia Date: 2010-10-08T17:21:46+09:00 Subject: [ruby-core:32719] Re: [Ruby 1.9-Feature#3845][Open] "in" infix operator --0016367fb5f56cdfbe049216b362 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, On Fri, Oct 8, 2010 at 9:16 AM, "Martin J. D=FCrst" wrote: > I would understand that if it were [a, b, c].included? x > But it's include?, so the order seems just fine. Easy to read as > "does [a, b, c] include x?". Any other order would feel strange, wouldn't > it? > > Also, an 'in?' method on Object has been proposed, so that you can write > x.in? [a, b, c] > That's very short, and fully object oriented pure Ruby, no syntactic suga= r > necessary. I totally agree : in as keyword is too different than the rest of Ruby syntax. I fear this kind of add would make Ruby syntax cryptic... > > 3) it is inefficient; new array object is created every times >> > > That's a problem for a good compiler/interpreter. There are many cases in > Ruby where similar stuff happen, and nevertheless, many people are using > Ruby. If it really needs to be fast, why not use C or so? > > What about x.in?(a, b, c) The Ruby naive implementation is really simple class Object def in?(*collections) collections.any?{|c| c.include?(self) } end end but I guess a C version could add optimizations (but are they needed ?) Regards, =C9tienne --=20 =C9tienne Vallette d'Osia --0016367fb5f56cdfbe049216b362 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

On Fri, Oct 8, 2010 at 9:16 AM, "= ;Martin J. D=FCrst" <duerst@it.aoyama.ac.jp> wrote:
I would understand that if it were [a, b, c].included? x
But it's include?, so the order seems just fine. Easy to read as
"does [a, b, c] include x?". Any other order would feel strange, = wouldn't it?

Also, an 'in?' method on Object has been proposed, so that you can = write
x.in? [a, b, c]
That's very short, and fully object oriented pure Ruby, no syntactic su= gar necessary.

I totally agree : in as keyword is too = different than the rest of Ruby syntax.
I fear this kind of add would ma= ke Ruby syntax cryptic...
=A0

=A0 3) it is inefficient; new array object is created every times

That's a problem for a good compiler/interpreter. There are many cases = in Ruby where similar stuff happen, and nevertheless, many people are using= Ruby. If it really needs to be fast, why not use C or so?


What about
=A0 x.in?(a, b, c)

The Ruby naive implementation is really simple=
=A0 class Object
=A0=A0=A0 def in?(*collections)
=A0=A0=A0=A0=A0 = collections.any?{|c| c.include?(self) }
=A0=A0=A0 end
=A0 end
but I guess a C version could add optimizations (but are they needed = ?)


Regards,

=C9tienne


--
=C9tienne Vallett= e d'Osia
--0016367fb5f56cdfbe049216b362--