Hi,

2010/9/22 Benoit Daloze <eregontp / gmail.com>:
> On 17 September 2010 12:30, Yusuke Endoh <redmine / ruby-lang.org> wrote:
>> Feature #3845: "in" infix operator
>>
>> What do you think?
>
> It is indeed more elegant than #include?, and reusing "in" is nice.

Thanks :-)


> | But, I thought of the following code:
> |
> | if n in 5..10
> |   # ...
> | end
> |
> | This code works only when "===" is used (of course, unless range is
> | specially handled).  So I prefer "===".
>
> Maybe if there is only one element to the right of "in",
>  it should be checked if having an #include? method and then call it ?
> (or check if it is Enumerable)

Hmm.  I received the similar opinion (via Japanese twitter).
I think that that makes the semantics complex (for me), but it is ok
as long as the behavior of usual cases is intuitive.


> Or maybe always use #include? when possible, and #== otherwise ?
>
> I think #=== is not really appropriate as it rarely check for
> inclusion, and would likely lead to unexpected results.

#=== has been used to check for inclusion in "case" statement, I think.
So it is not so inappropriate, imo.

  case n
  when  0... 5 then # ...
  when  5...10 then # ...
  when 10...20 then # ...
  end

  case var
  when Integer then # ...
  when String  then # ...
  end

-- 
Yusuke Endoh <mame / tsg.ne.jp>