On Tue, 10 Oct 2006 16:34:52 +0900, eden li 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? === is not commutative (nor is it intended to be), and it actually gets called in the other direction (the call it makes is String === C.new) To test how this works: class Class alias_method :old_case_equals, :=== def ===(other) puts "In Class.===: #{inspect}===#{other.inspect}" old_case_equals(other) end end be forewarned that doing something like this in IRB will cause very wierd output, since irb uses this method internally. --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/ I've added a signing subkey to my GPG key. Please update your keyring.