Ruby - Converting Objects to Other Classes

Introduction

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.

Demo

puts "12" + "10" 
puts 12 + 10 #   w w w .  j  a va 2s . c om
puts "12".to_i + "10".to_i 
puts 12.to_s + 10.to_s

Result

Related Topic