#--
# CREDIT William James
#++

class Integer

  # Convert integer to roman numeral.

  def to_roman
    "I =1       V =5      X = 10       L = 50
    C = 100    D = 500   M = 1000".
    scan( / ([A-Z]) \s *= \s* (\d+) /x ).
    map{|letter,val|  [ letter, val.to_i ] }.
    sort_by{|a| -a.last}.
    inject( [ "", self ] ){|roman, pair|
      [ roman.first + pair.first * (roman.last / pair.last),
        roman.last % pair.last ] }.
    first
  end
end
