From: David Alan Black Date: 2001-12-10T23:43:24+09:00 Subject: [ruby-talk:28087] Re: How does puts decide how to print a given object? Hello -- On Mon, 10 Dec 2001, Yukihiro Matsumoto wrote: > Hi, > > In message "[ruby-talk:28052] How does puts decide how to print a given object?" > on 01/12/10, "Harry Ohlsen" writes: > > |This got me to thinking how puts does its conversion to a string. I ask > |because (a) I'm surprised it doesn't just use to_s and because someone > |reading the article is bound to ask :-). > > "puts a" does > > if a is an array > puts each element of it > else > a = a.to_s > print a > print "\n" unless a[-1] == ?\n > end I can understand that for Array... but the thing that I found un-POLS-like is: class Thing < Array def to_s # ... end end and then Thing objects still get puts'd according to the rules of how Array is handled. In other words, not only is Array a special case, but overriding the puts behavior/results for Array subclasses is a special case. The former makes sense to me; the latter doesn't. Is this negotiable? :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav