Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/viral_seq/math.rb

Overview

additional functions for Class::Integer

Instance Method Summary collapse

Instance Method Details

#factorialInteger

factorial method for an Integer

Examples:

factorial for 5

5.factorial
=> 120

Returns:

  • (Integer)

    factorial for given Integer



160
161
162
163
164
165
166
# File 'lib/viral_seq/math.rb', line 160

def factorial
  if self == 0
    return 1
  else
    (1..self).inject(:*)
  end
end