Learn Ruby
String
3.12
Lesson

to_i to convert a string into a number

12 is a number. However “12” is not a number because it is in quotes and it is a string. If we try to add a number to string then we will get an error.

If we want to convert string into an integer then we need to use to_i method. to_i is a short form of “to integer”.

Let’s fix the last example by using to_i.