From: Sam Roberts Date: 2005-03-20T12:50:31+09:00 Subject: Re: how do you duck-type something to String, so String believes you? Quoting lists@bertram-scharpf.de, on Sat, Mar 19, 2005 at 07:58:39AM +0900: > Hi, > > Am Samstag, 19. M�r 2005, 02:21:15 +0900 schrieb Sam Roberts: > > Quoting flgr@ccan.de, on Tue, Mar 15, 2005 at 10:59:08PM +0900: > > > > class OneX; def ==(other); 1 == other; end; end > > => nil > > class UnityX; def ==(other); [1,1] == other; end; end > > => nil > > onex = OneX.new > > => # > > unityx = UnityX.new > > => # > > [1,1] == unityx > > => false > > 1 == onex > > => true > > > > Huh? It always happens? > > Fixnum and Float will call `other.== self' if they don't > find one of their relatives. > File `numeric.c', Function `num_equal()', line 806. That's surprising, I expected Numeric to only do this if other#to_int or other#to_float existed. If doing it all the time is a good idea, why don't Array and String do it that way? Sam