From: Michael Morin Date: 2008-08-31T04:57:46+09:00 Subject: Re: Show elements of array separated David A. Black wrote: > Hi -- > > On Sat, 30 Aug 2008, Michael Morin wrote: > >> Robert Klemme wrote: >>> irb(main):010:0> foo.inject {|a,b| "#{a}, #{b}"} >>> => "a, b, c" >>> irb(main):011:0> ["a"].inject {|a,b| "#{a}, #{b}"} >>> => "a" >>> irb(main):012:0> [].inject {|a,b| "#{a}, #{b}"} >>> => nil >>> irb(main):013:0> >>> >>> But note the empty Array case. >>> >>> Kind regards >>> >>> robert >> >> irb(main):006:0> [].inject{|a,b| "#{a}, #{b}" } or "" >> => "" > > Or: > > [].inject {...}.to_s > > In any case I think this is a job for #join :-) > > > David > Using inject you could do something to each element (capitalize, for example) at the same time. Though, you could just use arr.map.join if you wanted to do that. -- Michael Morin Guide to Ruby http://ruby.about.com/ Become an About.com Guide: beaguide.about.com About.com is part of the New York Times Company