/class_integer

Additional methods for the Integer class in Ruby

Primary LanguageRuby

class Integer

Creates additional methods for the Integer class in Ruby.

Currently includes:

  • Integer#to_roman
    • Returns any integer (up to 3999) in Roman numerals.
    • 1999.to_roman == 'MCMXCIX'
  • Integer#to_old_roman
    • Returns any integer (up to 3999) in old style Roman numerals (VIIII as opposed to IV in new Roman).
    • 1999.to_old_roman == 'MDCCCCLXXXXVIIII'
  • Integer#fact
    • Returns any integer factorial.
    • 4.fact == 24
  • Integer#to_english
    • Returns an integer as an english number.
    • Works up to trillions.
    • 1999.to_english == 'one thousand nine hundred ninety nine'
  • Integer#add_commas
    • Returns an integer as a string with commas.
    • 1999.add_commas == '1,999'
  • test.rb
    • Quick test that returns an array of true/false responses based on methods.
  • Error checking for incorrect inputs.

To later include:

  • Additional ArgumentErrors for bad inputs.