Christophe Grandsire wrote:
> En r?ponse ? Jacob Fugal :
>>
>> On the right track, but it's actually the right argument. That is:
>>
>>   irb(main):001:0> String === "string"
>>   => true
>>
>
> You're right of course! I keep forgetting that order :( .
>
>> That's because the left hand side is the receiver (=== is just
>> another method). When the receiver is a Class, Class#=== is called.
>>
>>   irb(main):002:0> String.===( "string" )
>>   => true
>>
>
> It makes sense, but I still have difficulties remembering it :( .
>
>>
>> A when clause for a case statement evaluates using === with the when
>> argument as the receiver and case argument as argument. So:
>>
>
> Yes, and although the order makes sense, from a functional point of
> view, it is difficult to get my head around the idea that case
> indicates the argument rather than the receiver.

If you think about it for a moment you'll see that it's the only
reasonable approach: the expression after the case is the item to test and
all expressions after when denomiate conditions.  You can for example do
this, which might make it clearer...

def Condition(&b)
  class <<b
    alias === []
  end
  b
end

case a_number
  when Condition {|x| x < 10}
  ...
end

Of course, you can have this easier as in

case
  when a_number < 10
  ...
end

But for more complicated conditions you might want to assign it to a const
so you can reuse it efficiently.

Kind regards

    robert