Skip to content

Instantly share code, notes, and snippets.

@nazgob
Created July 11, 2010 13:55
Show Gist options
  • Save nazgob/471567 to your computer and use it in GitHub Desktop.
Save nazgob/471567 to your computer and use it in GitHub Desktop.
Roman numbers / method missing
class Roman
def self.method_missing name, *args
roman = name.to_s
roman.gsub!("IV" , "IIII" )
roman.gsub!("IX" , "VIIII" )
roman.gsub!("XL" , "XXXX" )
roman.gsub!("XC" , "LXXXX" )
(roman.count("I" ) +
roman.count("V" ) * 5 +
roman.count("X" ) * 10 +
roman.count("L" ) * 50 +
roman.count("C" ) * 100)
end
end
puts Roman.X
puts Roman.XC
puts Roman.XII
puts Roman.X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment