Module: ActiveObject::Integer
- Defined in:
- lib/active_object/integer.rb
Instance Method Summary collapse
Instance Method Details
#factorial ⇒ Object
10 11 12 13 14 |
# File 'lib/active_object/integer.rb', line 10 def factorial return 1 if zero? 2.upto(self).inject(1) { |acc, elem| acc * elem } end |
#of(&block) ⇒ Object
16 17 18 |
# File 'lib/active_object/integer.rb', line 16 def of(&block) ::Array.new(self, &block) end |
#roman ⇒ Object
20 21 22 23 24 25 |
# File 'lib/active_object/integer.rb', line 20 def roman return '' if zero? return "-#{(-self).roman}" if negative? ROMAN_VALUES.each { |key, val| return("#{key}#{(self - val).roman}") if val <= self } end |
#time ⇒ Object
27 28 29 |
# File 'lib/active_object/integer.rb', line 27 def time ::Time.at(self) end |