Guest User

Untitled

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