From: Guillaume Marcais Date: 2004-04-05T00:02:47+09:00 Subject: Re: deciding between ruby and python Just a as we are on the subject. Should Ojbect#to_s return self.to_str if it is defined instead of the default value? EX: class Toto; end Toto.new.to_s # => "#" class Toto; def to_str; "toto"; end; end Toto.new.to_s The last statement today returns "<#Toto:...>. Should it return "toto" instead? Meaning, shouldn't the string representation of an object (returned by #to_s) be the same as it String masqueraded behavior? Of course, nothing prevents you from to define to_s as to_str if you want... Just wondering about what default behavior makes the most sense. Guillaume. Le 4 avr. 04, � 10:18, Yukihiro Matsumoto a �crit : > Hi, > > In message "Re: deciding between ruby and python" > on 04/04/04, "David A. Black" writes: > > |That said, I've also never been 100% sure why String#+ couldn't be > |more tolerant -- that is, allow objects to present their #to_s > |representations, rather than insisting that they either be Strings or > |have a #to_str method. > > Pre 1.0 Ruby was very tolerant about types: 1 + "2" gave 3, and > "2" + 1 gave "21". > > But this tend to hide the type mismatch error, so that I had to follow > the "crash early" principle from Pragmatic Programmers. > > matz. >