Created
April 24, 2009 01:02
-
-
Save kristopher/100868 to your computer and use it in GitHub Desktop.
This file contains 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 Array | |
def sum | |
inject(0) do |memo, i| | |
memo += i | |
end | |
end | |
end | |
sum_method = Array.instance_method(:sum) | |
Array.send(:remove_method, :sum) | |
[1,2].sum | |
=> NoMethodError: undefined method `sum' for [1, 2]:Array | |
sum_method.bind([1,2]).call | |
=> 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment