From: "Bilyk, Alex" Date: 2008-10-08T10:32:26+09:00 Subject: Re: Looking for more Ruby-like way to create an array converted_array = original_array.inject([]) {|a, line| a << (line.to_f * 100)} -----Original Message----- From: David A. Black [mailto:dblack@rubypal.com] Sent: Tuesday, October 07, 2008 6:19 PM To: ruby-talk ML Subject: Re: Looking for more Ruby-like way to create an array Hi -- On Wed, 8 Oct 2008, William James wrote: > On Oct 7, 4:33 pm, Steve Nicholson wrote: >> I'm creating an array that is the result of the members of another >> array each multiplied by 100. Here's what I have: >> >> converted_array = [] >> original_array.each {|line| converted_array << line.to_f * 100} >> >> This works, but I'm wondering if there is a more idiomatically "Ruby" >> way of doing it. >> -- >> Posted viahttp://www.ruby-forum.com/. > > irb(main):001:0> a = 2,3,5,8 > => [2, 3, 5, 8] > irb(main):002:0> a.map!{|n| n*10 } > => [20, 30, 50, 80] > irb(main):003:0> a > => [20, 30, 50, 80] That's a little different, since it leaves you without the original array (which may in fact be OK, but is an important difference). David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!