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

From: Yusuke ENDOH <mame@...>
Date: 2010-10-05 14:28:59 UTC
List: ruby-core #32696
Hi,

2010/9/24 "Martin J. D=FCrst" <duerst@it.aoyama.ac.jp>:
> Just my two cents, but I don't see why this case is important enough to
> warrant deviating from the usual, object-oriented syntax (which may not
> always look optimal, but is easy and straightforward).


Thank you for your comment.

Indeed, an idiom [a, b, c].include?(x) can be used as a substitute.
However, it has three problems:

  1) the word order is weird; x should appear first (at least, many
     people feel so)
  2) the idiom is too long (even though it is often used)
  3) it is inefficient; new array object is created every times

Also, x =3D=3D a || x =3D=3D b || x =3D=3D c can be used.  It has another p=
roblem:
it becomes very verbose when "x" is long.

    http_request.http_method =3D=3D :get  ||
    http_request.http_method =3D=3D :post ||
    http_request.http_method =3D=3D :put  ||
    http_request.http_method =3D=3D :delete

  vs.

    http_request.http_method in :get, :post, :put, :delete


What is worse is that we often want to write this kind of code.
If we rarely wrote this kind of code, I would think that new syntax
was not needed.

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

In This Thread