Created
June 13, 2012 23:33
-
-
Save perspectivezoom/2927147 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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