From: Rein Henrichs Date: 2010-06-18T12:50:05+09:00 Subject: Re: Idiomatic Printing an array with commas On 2010-06-17 20:08:32 -0700, Chuck Brotman said: > ".inspect", ".join", "*". Of course, there isn't just one way to get > the job done in Ruby! > > I appreciate all the tips > > > Thanks, > > Chuck Well, Array#inspect makes use of behavior identical to that of Array#join. You could* implement it as: class Array def inspect '[' << map{|item| item.inspect}.join(', ') << ']' end end Also, Array#join and Array#* are synonyms. So there's way closer to one way than to many. ;) * this naive implementation fails on recursive arrays and is less efficient than the one used by Rubinius**, which combines the #map and #join into a single #each: http://github.com/evanphx/rubinius/blob/master/kernel/common/array.rb#L915-926 ** Rubinius source-diving is a great way to find out a Ruby reference implementation for something written in C in MRI or YARV Rubies. -- Rein Henrichs http://puppetlabs.com http://reinh.com