From: Chris Hulan Date: 2006-07-07T04:11:37+09:00 Subject: Re: Achieving Equality unknown wrote: >> I get a == rwd #=> true ? > > Ah, it's simplified example of what I'm actually doing. So in this case > the integers auto-coerce it seems. Try: > > a, b = "1", "1" > > Which is probably a clue that can can be doen via #coerce, but I'm not > sure how. > > T. I suggest modifying your == method to: def ==( other ) #p "#{@read.call} == #{other.inspect}" if other.kind_of?(RWDelegator) other == @read.call else @read.call == other end end To compare to other objects you can: 1) write conversion methods (i.e. to_s) and than convert the RWDelegator to the appropriate type when comparing (i.e. rwd.to_s == "1") 2) re-write the conversion methods of the other classes to handle your RWDelegator class appropriately: class String alias old== == def ==(other) if other.kind_of(RWDelegator) other == self else old==(other) end end Cheers -- Posted via http://www.ruby-forum.com/.