From: "David A. Black" Date: 2004-04-04T23:04:35+09:00 Subject: Re: deciding between ruby and python HI -- On Sun, 4 Apr 2004, Dan Doel wrote: > Ah, yes. Upon going back and reading I had it backwards. Serves me right for > trying to rely on my memory alone. > > I'm conflicted in my opinions. On the one hand, perhaps it'd be good > for #join to only use #to_str to convert, since that means objects > are allowed to be auto-converted, and that would be appropriate for > duck typing (that is, the object is saying it acts like a string > through this conversion). Calling #to_s doesn't mean the object is > "supposed" to be interchangeable with a string. I think there's a difference between an object acting like a string and an object saying it acts like a string. (Does that make any sense?) I've always understood #to_str as mainly for cases where an object is acted upon directly -- like: "x" + obj # obj had better be able to masquerade as a String rather than a case like #join where, so to speak, the objects (the array elements) are asked for string representations of themselves, rather than for themselves-being-Strings. 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. The whole concept of "wanting a String object" and having a mechanism that makes an object appear that way strikes me as uncharacteristically classname-centric for Ruby. Then again, perhaps there's a certain amount of classname-based things that have to happen in order to bootstrap the lovely object-centric programming space we know and love. David -- David A. Black dblack@wobblini.net