Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
Created June 13, 2012 23:33
Show Gist options
  • Save perspectivezoom/2927147 to your computer and use it in GitHub Desktop.
Save perspectivezoom/2927147 to your computer and use it in GitHub Desktop.
class Numeric
def factorial()
self < 0 ? raise("You can't take the factorial of a negative number") : factorial_h(1,self)
end
def factorial_h(accum, n)
n <= 1 ? accum : factorial_h(accum * n, n -1 )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment