I am trying to take a number from 0-999999999 and produce the word for that number. I have a hash with the numbers => words. This worked for numbers 0 - 999, I wanted to add if statements to handle the number if it was > 1000 and < 1000000. If so I would divide the number by 1000 and mod 1000 +1000. But I get this error.
ERROR: say.rb:44:in _in_english': stack level too deep (SystemStackError)
from say.rb:45:in
_in_english'
from say.rb:33:in `in_english'
from say.rb:65
Code:
private
def _in_english(number)
if number > 1000000 || number <1000000000
_in_english(number/1000000) + _in_english(number%1000000+1000000) <== Line it fails on!
elsif number > 1000 || number <1000000
_in_english(number/1000) + _in_english(number%1000+1000)
else
index = ENGLISH.keys.select {|n| n <= number}.max
ENGLISH[index] + (index < number ? " " + _in_english(number-index) : '')
end
end