Created
June 2, 2016 00:54
-
-
Save whitehat101/5af53ca74fb93196c084228971232dfe to your computer and use it in GitHub Desktop.
Adds :fact to Fixnum
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
module WhiteHat101 | |
module Factorial | |
# returns 1 for input < 1 | |
def fact | |
(1..self).inject 1, :* | |
end | |
alias_method :!, :fact | |
end | |
end | |
Fixnum.send :include, WhiteHat101::Factorial | |
# 6.fact => 720 | |
# 0.fact => 1 | |
# 3.! => 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment