TOP

Ruby: Convert to Integer

To convert a string or other object into an integer (number) do this:

"23".to_i

This will produce 23 (as a number)

If you do something like this:

"Hello".to_i

You will get 0 returned, because Ruby can’t understand that object ans translate it into a number.

TOP

Ruby: Convert to String

To convert a number to a string in Ruby, do this:

40.to_s