Skip to content

Instantly share code, notes, and snippets.

@excid3
Created July 3, 2012 17:48
Show Gist options
  • Select an option

  • Save excid3/3041333 to your computer and use it in GitHub Desktop.

Select an option

Save excid3/3041333 to your computer and use it in GitHub Desktop.
def word_to_number(word)
onesPlace = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
tensPlace = [nil, 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
onesPlace.index(word) || tensPlace.index(word) * 10
end
puts word_to_number('one')
puts word_to_number('two')
puts word_to_number('three')
puts word_to_number('four')
puts word_to_number('five')
puts word_to_number('six')
puts word_to_number('seven')
puts word_to_number('eight')
puts word_to_number('nine')
puts word_to_number('ten')
puts word_to_number('twenty')
puts word_to_number('thirty')
puts word_to_number('forty')
puts word_to_number('fifty')
puts word_to_number('sixty')
puts word_to_number('seventy')
puts word_to_number('eighty')
puts word_to_number('ninety')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment