Class: Integer
Constant Summary collapse
- ROMAN_VALUES =
{ "M" => 1000, "CM" => 900, "D" => 500, "CD" => 400, "C" => 100, "XC" => 90, "L" => 50, "XL" => 40, "X" => 10, "IX" => 9, "V" => 5, "IV" => 4, "I" => 1 }
Instance Method Summary collapse
Instance Method Details
#factorial ⇒ Object
19 20 21 22 |
# File 'lib/active_object/integer.rb', line 19 def factorial return(1) if zero? 2.upto(self).inject(1) { |product, n| product * n } end |
#of(&block) ⇒ Object
24 25 26 |
# File 'lib/active_object/integer.rb', line 24 def of(&block) Array.new(self, &block) end |
#roman ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/active_object/integer.rb', line 28 def roman return("") if zero? return("-#{(-self).roman}") if self < 0 ROMAN_VALUES.each do |key, value| return(key + (self - value).roman) if value <= self end end |
#time ⇒ Object
37 38 39 |
# File 'lib/active_object/integer.rb', line 37 def time Time.at(self) end |