On 10/10/06, eden li <eden.li / gmail.com> wrote:
> Can someone explain why my class's === method is never called in the
> following code?
>
> irb(main):001:0> class C; def ===(k); puts "===(#{k.inspect}) called";
> true; end; end
> => nil
> irb(main):002:0> case C.new; when String; 'is a String'; else; 'not a
> String'; end
> => "not a String"
>
> I expected "===(String) called" to be printed out somewhere, somewhat
> like:
>
> irb(main):003:0> C.new === String
> ===(String) called
> => true
>
> Am I misunderstanding how case/when works?
>
>
>

In case statements such as
 case(object)
 when otherObject
  puts "Match!"
 else
  puts "No match"
 end

The === is not called on object but rather on otherObject.

Farrel