Ruby - Converting Objects to Other Classes


Numbers, strings, symbols, and other types of data are objects belonging to various classes.

Numbers belong to Fixnum, Bignum, Float, and/or Integer classes.

Strings are objects of the String class.

Symbols are objects of the Symbol class.

You can convert objects between the different classes, so a number can become a string and a string can become a number.


puts "12" + "10" 
puts 12 + 10 # from  w  w  w .j a  v a2  s .  c om
puts "12".to_i + "10".to_i 
puts 12.to_s + 10.to_s


Related Topic