Module: ActiveObject::Integer

Defined in:
lib/active_object/integer.rb

Instance Method Summary collapse

Instance Method Details

#factorialObject



7
8
9
10
11
# File 'lib/active_object/integer.rb', line 7

def factorial
  return 1 if zero?

  2.upto(self).inject(1) { |acc, elem| acc * elem }
end

#of(&block) ⇒ Object



13
14
15
# File 'lib/active_object/integer.rb', line 13

def of(&block)
  Array.new(self, &block)
end

#romanObject



17
18
19
20
21
22
# File 'lib/active_object/integer.rb', line 17

def roman
  return '' if zero?
  return "-#{(-self).roman}" if negative?

  ROMAN_VALUES.each { |key, val| return("#{key}#{(self - val).roman}") if val <= self }
end

#timeObject



24
25
26
# File 'lib/active_object/integer.rb', line 24

def time
  Time.at(self)
end