From: Gregory Brown Date: 2008-08-01T05:50:14+09:00 Subject: Re: Needing help with which to_s gets called On Thu, Jul 31, 2008 at 4:41 PM, Sebastian Hungerecker wrote: > John Winters wrote: >> Thanks for that. There certainly seems to be some sort of >> special-casing going on, but it's more widespread than just puts. > > You're right. join special cases arrays as well, joining nested arrays as well > instead of to_sing them (that or it just calls flatten on the array before > starting it's work). I guess this is an example of core class special cases that I was worried about in an earlier thread today. I really don't think it's a good practice to subclass core classes unless you are only adding new behaviour. Wrapping and delegating is much more predictable. That having been said, the problem goes away if you first explicitly map using to_s before the join(), but this is an indication of the kind of hacks subclassing core objects like Array will force upon you :-/ def to_s "[Baker: #{@contents.map { |e| e.to_s }.join(", ")}]" end