Forum: Ruby convert each element in an array

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E17632fab00b930ea3b30e1b98f39675?d=identicon&s=25 Jeppe Jakobsen (Guest)
on 2006-02-18 18:56
(Received via mailing list)
Hi, I can't find out how to convert each integer in my array to a float.
I've tried:

array.each {|x| x.to_f}

But it did not work.

Can anyone tell me the correct method?
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-02-18 19:36
(Received via mailing list)
On Feb 18, 2006, at 12:53 PM, Jeppe Jakobsen wrote:

> --
> "winners never quit, quitters never win"

array.map! { |x| x.to_f } # for in place modification
array2 =  array.map { |x| x.to_f } # if you want a new array with
float values without messing up the old array
E17632fab00b930ea3b30e1b98f39675?d=identicon&s=25 Jeppe Jakobsen (Guest)
on 2006-02-18 21:37
(Received via mailing list)
Thanks!

2006/2/18, Logan Capaldo <logancapaldo@gmail.com>:
This topic is locked and can not be replied to.