Created
June 14, 2012 03:47
-
-
Save jessieay/2927897 to your computer and use it in GitHub Desktop.
I am learning recursion
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 Fixnum | |
def factorial | |
if self < 0 | |
raise "You can't take the factorial of a negative number." | |
elsif | |
self == 0 | |
1 | |
else | |
self * (self-1).factorial | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment