Ruby – Convert string numbers( in word format) to integer ruby

ruby

If you have a string ten, is it possible to convert it to an integer 10 in Ruby? (maybe in rails?)

I value the developers at tryruby.org, and in their tutorial here, it specifically says "to_i converts things to integers (numbers.)" I am wondering why they didn't say "to_i converts STRINGS to integers (numbers.)"

What variable types can be converted from their type to an integer?

Best Answer

Check out this gem for handling word to number conversions.

From the readme:

require 'numbers_in_words'
require 'numbers_in_words/duck_punch'

112.in_words
#=> one hundred and twelve
"Seventy million, five-hundred and fifty six thousand point eight nine three".in_numbers
#=> 70556000.893