Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

55 lines (45 sloc) 0.892 kb
module RomanNumeral
ORDER = { 1000 => "M",
900 => "CM",
500 => "D",
100 => "C",
90 => "XC",
50 => "L",
10 => "X",
9 => "IX",
5 => "V",
4 => "IV",
1 => "I"}
def to_roman
RomanNumeral.convert_numeric_to_roman self
end
def self.convert_numeric_to_roman(number)
output = ""
ORDER.each do |key,value|
# puts "key: #{key}: value: #{value}"
times = number / key
while number >= key
number = number - key
output = output + value
end
end
output
end
end
class Numeric
include RomanNumeral
end
class RomanNumeralString
attr_accessor :string
def initialize(roman)
self.string = roman
end
def to_i
0
end
end
class String
def to_roman
RomanNumeralString.new(self).to_i
end
end
Jump to Line
Something went wrong with that request. Please try again.