Last active
August 29, 2015 14:23
-
-
Save ahmadseleem/96683a779dcc078d8e1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert Decimals to Roman numerals... | |
# | |
module Roman | |
ROMAN_STEPS = | |
{ | |
'M' => 1000, 'CM' => 900, | |
'D' => 500, 'CD' => 400, | |
'C' => 100, 'XC' => 90, | |
'L' => 50, 'XL' => 40, | |
'X' => 10, 'IX' => 9, | |
'V' => 5, 'IV' => 4, | |
'I' => 1 | |
} | |
def to_roman | |
deci = self | |
roman = '' | |
ROMAN_STEPS.each do |k, v| | |
while deci > v - 1 | |
roman += k | |
deci -= v | |
end | |
break if deci == 0 | |
end | |
roman | |
end | |
end | |
# Extend Numeric Class | |
class Numeric | |
include Roman | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment