Skip to content

Instantly share code, notes, and snippets.

@benhorne44
Created January 8, 2014 03:01
Show Gist options
  • Save benhorne44/8311074 to your computer and use it in GitHub Desktop.
Save benhorne44/8311074 to your computer and use it in GitHub Desktop.
class Fixnum
def to_roman
number = self
conversions.map do |decimal, roman|
quotient, modulus = number.divmod(decimal)
number = modulus
roman * quotient
end.join
end
def conversions
[
[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment