Method: Integer#factorial
- Defined in:
- lib/core/facets/integer/factorial.rb
#factorial ⇒ Object Also known as: fac
Calculate the factorial of an integer.
2.factorial #=> 2
3.factorial #=> 6
4.factorial #=> 24
CREDIT: Malte Milatz
11 12 13 14 15 16 |
# File 'lib/core/facets/integer/factorial.rb', line 11 def factorial return 1 if zero? f = 1 2.upto(self) { |n| f *= n } f end |