Skip to content

Instantly share code, notes, and snippets.

@esquinas
Created May 12, 2016 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esquinas/cb3707735a13823930a6d7c5860cc739 to your computer and use it in GitHub Desktop.
Save esquinas/cb3707735a13823930a6d7c5860cc739 to your computer and use it in GitHub Desktop.
Simplest factorial function in Ruby
# 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