Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/caruby/helpers/roman.rb
Instance Method Summary collapse
-
#to_roman ⇒ String
The roman numeral equivalent of this integer.
Instance Method Details
#to_roman ⇒ String
Returns the roman numeral equivalent of this integer.
20 21 22 23 24 25 26 27 |
# File 'lib/caruby/helpers/roman.rb', line 20 def to_roman if self < 1 or self > 10 then raise ArgumentError.new("#{self} cannot be converted to a roman numeral in the range I-X") elsif self < 4 then 'I' * self elsif self < 6 then ('I' * (5 - self)) + 'V' elsif self < 9 then 'V' + ('I' * (self - 5)) else ('I' * (10 - self)) + 'X' end end |