Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Fixnum
- def to_roman
- raise "NoRomanLiteralException" unless (1..3999) === self
- ([1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1].zip \
- ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]).inject(["",self]) \
- do |(string, remaining),(value, letters)|
- [string + letters * (remaining / value), remaining % value]
- end [0]
- end
- end
Add Comment
Please, Sign In to add comment