lib/core/facets/integer/factorial.rb in facets-2.1.3 vs lib/core/facets/integer/factorial.rb in facets-2.2.0
- old
+ new
@@ -1,40 +1,23 @@
-# = FILE
-#
-# interger/factorial.rb
-#
-# = DESCRIPTION
-#
-# Factorial extension for Integer class.
-#
-# = AUTHORS
-#
-# CREDIT Malte Milatz
-
-#
-
class Integer
# Calculate the factorial of an integer.
#
# 2.factorial #=> 2
# 3.factorial #=> 6
# 3.factorial #=> 24
#
+ # CREDIT: Malte Milatz
def factorial
return 1 if zero?
f = 1
2.upto(self) { |n| f *= n }
f
end
- #--
- # TODO Pick one of these and deprecate the other. But which?
- #++
alias_method( :fac, :factorial )
- alias_method( :fact, :factorial )
#-- OLD CODE
#def factorial
# return 1 if self == 0
# #self == 0 ? 1 : ( self * (self-1).factorial )
@@ -42,31 +25,5 @@
# return self < 0 ? -f : f
#end
#++
end
-
-
-
-# _____ _
-# |_ _|__ ___| |_
-# | |/ _ \/ __| __|
-# | | __/\__ \ |_
-# |_|\___||___/\__|
-#
-=begin test
-
- require 'test/unit'
-
- class TCInteger < Test::Unit::TestCase
-
- def test_factorial
- assert_equal( 1, 0.factorial )
- assert_equal( 1, 1.factorial )
- assert_equal( 2, 2.factorial )
- assert_equal( 6, 3.factorial )
- assert_equal( 24, 4.factorial )
- end
-
- end
-
-=end