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.