From: Robert Klemme Date: 2005-08-27T00:08:47+09:00 Subject: Re: to_s and to_str 2005/8/26, Mark Volkmann : > Here's what I've learned so far. > 1) Every object has to_s because Object provides a default implementation. > 2) Some classes override to_s to return a more useful String. > 3) to_str should only be implemented in classes whose objects can > logically be used as Strings. > > If you're going to implement to_str in a class, is there a reason why > it might return something different than to_s? Is one considered a > human-readable representation and the other something else? to_s is rather human readable while to_str should return a string representation of the value that might be used to reconstruct it. Note that you should have both even if they return the same because to_str is used in some methods to convert parameters. > Isn't "can be logically used as Strings" a somewhat subjective thing? Yes. Kind regards robert