How do you do (explicit) type conversion in ruby? I just want to make
/“2” + “3” = 5/ , but it, of course, gives me /“23”/ and not /5/.
Thomas Jollans
How do you do (explicit) type conversion in ruby? I just want to make
/“2” + “3” = 5/ , but it, of course, gives me /“23”/ and not /5/.
Thomas Jollans
Thomas Jollans wrote:
How do you do (explicit) type conversion in ruby? I just want to make
/“2” + “3” = 5/ , but it, of course, gives me /“23”/ and not /5/.Thomas Jollans
“2”.to_i + “3”.to_i
Regards,
Dan
–
a = [74, 117, 115, 116, 32, 65, 110, 111, 116, 104, 101, 114, 32, 82]
a.push(117,98, 121, 32, 72, 97, 99, 107, 101, 114)
puts a.pack(“C*”)
irb(main):001:0> ‘2’.to_i + ‘3’.to_i
5
each class has (does not have) it’s own conversion methods. so, for instance,
check the docs for String to see how to convert to a number.
-a
On Tue, 25 Feb 2003, Thomas Jollans wrote:
How do you do (explicit) type conversion in ruby? I just want to make
/“2” + “3” = 5/ , but it, of course, gives me /“23”/ and not /5/.
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================