Roman Numeral Converter
My Roman Numeral converter class I constructed in my 1st phase of Dev Bootcamp Chicago.
<br/>
With Recursion!!!!
class RomanNumerals
def initialize
re_pop
end
def converter(test_number, discard = 0, key = @roman_numbers.keys.first)
return "" if test_number == 0
(@roman_numbers[key] * (test_number / key)) +
converter(test_number % key, @roman_numbers.delete(key))
end
def re_pop
@roman_numbers = {
1000 => "M",
900 => "CM",
500 => "D",
400 => "CD",
100 => "C",
90 => "XC",
50 => "L",
40 => "XL",
10 => "X",
9 => "IX",
5 => "V",
4 => "IV",
1 => "I"
}
end
end
Language: Ruby | User: ShadyPenguin | Created: Nov 15, 2013 | Tags: Ruby