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 to string_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 of integer_number, which is 123, to the console.