From: Joel VanderWerf Date: 2006-10-21T09:04:05+09:00 Subject: Re: Array#to_s in Ruby 1.9 Head Ross Bamford wrote: > On Fri, 2006-10-20 at 06:34 +0900, gwtmp01@mac.com wrote: >> Mauricio Fernandez writes in http://eigenclass.org/hiki.rb?Changes+in >> +Ruby+1.9+update+5 >> that Ruby 1.9 Head has changed Array#to_s to be an alias for >> Array#to_inspect. >> >> What is the motivation for that change? >> print a >> becomes >> a.each { |x| print x } >> >> It seems like an unnecessary change that takes away a very nice >> default behavior. > > FWIW I find I need 'puts ary.inspect' much more often than 'puts ary', > so I think this is a good change. (Why 'puts ary.inspect' instead of 'p ary' ?) I suspect there is a fair amount of code that depends on print a being the same as print *a This would be the case if you are thinking of an array of strings as an array of lines. For example, if you are writing a method whose input, a, is the contents of a text file _either_ as a string _or_ as an array of lines, then print a has the same behavior on all inputs. With the change in Array#to_a, you don't have this nice duck-typing, but you get it back if you use splat: print *a (that works when a is a string, at least in 1.8.4) I'm not against the change, just thinking about damage control. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407