From: "David A. Black" Date: 2008-10-08T10:19:02+09:00 Subject: Re: Looking for more Ruby-like way to create an array --1926193751-162308388-1223428863=:3402 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-162308388-1223428863=:3402" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-162308388-1223428863=:3402 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Wed, 8 Oct 2008, William James wrote: > On Oct 7, 4:33=A0pm, 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: >> >> =A0 converted_array =3D [] >> =A0 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 =3D 2,3,5,8 > =3D> [2, 3, 5, 8] > irb(main):002:0> a.map!{|n| n*10 } > =3D> [20, 30, 50, 80] > irb(main):003:0> a > =3D> [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 --=20 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! --1926193751-162308388-1223428863=:3402-- --1926193751-162308388-1223428863=:3402--