From: Glen Holcomb Date: 2008-08-01T05:35:03+09:00 Subject: Re: Needing help with which to_s gets called ------=_Part_108451_970780.1217536551762 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Thu, Jul 31, 2008 at 2:31 PM, John Winters wrote: > Sebastian Hungerecker wrote: > > John Winters wrote: > >> Why when Able is a sub-class of Array does my to_s method get ignored? > > > > Because puts special cases arrays, not calling to_s on them at all. > > If you compare puts [1,2,3] to puts [1,2,3].to_s you will see > > that this is the case (puts [1,2,3] is just like puts 1,2,3 printing > > each number on its own line instead of having it all in one line like > > you get with to_s. > > Thanks for that. There certainly seems to be some sort of > special-casing going on, but it's more widespread than just puts. > > I tried the test case which you suggested and see exactly what you said. > However I also went back to my original code and changed the "puts" line > from: > > puts item > > to: > > output = item.to_s > puts output > > and I still get the same oddity so it's clearly not just puts doing it. > > Do you have a reference where I can read up more on this? > > TIA, > John > -- > Posted via http://www.ruby-forum.com/. > > output is an instance of Baker so Ruby will invoke Baker's to_s method. -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_108451_970780.1217536551762--