ruby string to int
string_number = "123"
integer_number = string_number.to_i
puts integer_number
string_number
variable is assigned the value"123"
.to_i
method is applied tostring_number
which converts the string"123"
to an integer.- The resulting integer value is stored in the variable
integer_number
. puts
is used to output the value ofinteger_number
, which is123
, to the console.