call the to_s method on many built-in classes to return the contents of the object as a string : Convert to String « String « Ruby






call the to_s method on many built-in classes to return the contents of the object as a string


puts 1000.to_s
puts [1,2,3].to_s
puts ({ :name => 'Fred', :age => 10 }).to_s

 








Related examples in the same category

1.Convert an object to a string with to_s.
2.change the output on the fly with the %s format flag and %: