Created
May 12, 2016 19:08
-
-
Save esquinas/cb3707735a13823930a6d7c5860cc739 to your computer and use it in GitHub Desktop.
Simplest factorial function in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add factorial method to Math standard module in Ruby | |
module Factorial | |
def factorial(n) | |
Integer Math.gamma(n.to_i + 1) | |
end | |
end | |
Math.extend Factorial |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment