Class: Integer

Inherits:
Object show all
Defined in:
lib/darkext/integer.rb

Instance Method Summary collapse

Instance Method Details

#factObject

Computes the factorial of the Integer

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/darkext/integer.rb', line 5

def fact
  raise ArgumentError.new('Cannot compute factorial of negative number') if 0 > self
  return 1 if self.zero?
  return (1..self).to_a.product
end