Ruby to_s
It’s not uncommon to use .to_s
in Ruby to cast a number to string.
It’s also a way to take an API response in a hash and log it safely.
String interpolation in Ruby also calls .to_s
– automatically.
person = {:name => 'Juanita',
:salary => 200000,
:title => 'Senior Software Engineer'}
person.to_s
# "{:name=>\"Juanita\", :salary=>200000, :title=>\"Senior Software Engineer\"}"
"#{person}"
# "{:name=>\"Juanita\", :salary=>200000, :title=>\"Senior Software Engineer\"}"