From: FireAphis Date: 2007-08-09T13:34:59+09:00 Subject: Re: Iterating list in pairs On Aug 8, 4:43 pm, dbl...@rubypal.com wrote: > Hi -- > > On Wed, 8 Aug 2007, FireAphis wrote: > > Hello, > > > I need to iterate through a list and handle two elements on every > > iteration. That is I'd like to do something like > > > [1,2,3,4,5].each { |x, y| puts x.to_s + y.to_s } > > > 12 > > 23 > > 34 > > 45 > > [1,2,3,4,5].inject {|a,b| puts "#{a}#{b}"; b } > > David > > -- > * Books: > RAILS ROUTING (new!http://www.awprofessional.com/title/0321509242) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) Short and elegant!