From: Brian Candler Date: 2010-05-11T17:58:07+09:00 Subject: Re: In Ruby, can the coerce() method know what operator it is th Jian Lin wrote: > So what if most operators can use this method, but not when it is (a - > b) != (b - a) situation? Can coerce() know which operator it is, and > just handle those special cases, while just using the simple [self, > something] to handle all the other cases where (a op b) == (b op a) ? > (op is the operator). In ruby 1.8 and 1.9, != is syntactic sugar for "not ==". So put the logic you want in your == method. class Foo def ==(other) puts "Yay!" false end end puts "Boing!" if Foo.new != Foo.new # prints: # Yay! # Boing! -- Posted via http://www.ruby-forum.com/.