From: matz@... (Yukihiro Matsumoto) Date: 2001-12-11T02:59:54+09:00 Subject: [ruby-talk:28113] Re: How does puts decide how to print a given object? Hi, In message "[ruby-talk:28087] Re: How does puts decide how to print a given object?" on 01/12/10, David Alan Black writes: |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? :-) I have experimented about this issue for the last few weeks on the latest CVS. I changed puts to stop array handling, and call to_s for every object. But.. (1) it breaks some code. (2) to recover (1), I changed Array#to_s behavior, but things went worse. notice recent Rubicon failures? (3) unlike other objects, arrays are sometimes very big. imagine the code like 'puts File.readlines("bigfile")'. calling to_s inside wastes huge memory region. So my conclusion is Array should be treated specially by puts. It is false assumption that puts should call to_s. Hooking some Array method (like in [ruby-talk:28091]) is worth consider though. matz.