Skip to content

Instantly share code, notes, and snippets.

@manleyhimself
Created October 11, 2013 16:08
Show Gist options
  • Select an option

  • Save manleyhimself/6937493 to your computer and use it in GitHub Desktop.

Select an option

Save manleyhimself/6937493 to your computer and use it in GitHub Desktop.
class Integer
@@roman_numerals = {
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",
}
def to_roman
roman = ""
arabic = self
@@roman_numerals.each do |arabic_key, roman_value|
roman << roman_value * (arabic / arabic_key)
arabic = arabic % arabic_key
end
roman
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment