module ActiveObject::Integer

Public Instance Methods

factorial() click to toggle source
# File lib/active_object/integer.rb, line 21
def factorial
  return 1 if zero?

  2.upto(self).inject(1) { |acc, elem| acc * elem }
end
factors() click to toggle source
# File lib/active_object/integer.rb, line 27
def factors
  limit = Math.sqrt(self).floor

  (1..limit).each_with_object([]) do |i, acc|
    next unless (self % i).zero?

    acc.push(i)

    sq_num = (self / i)
    acc.push(sq_num) if sq_num != i
  end
end
of(&block) click to toggle source
# File lib/active_object/integer.rb, line 40
def of(&block)
  ::Array.new(self, &block)
end
roman() click to toggle source
# File lib/active_object/integer.rb, line 44
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() click to toggle source
# File lib/active_object/integer.rb, line 51
def time
  ::Time.at(self)
end