Skip to content

Instantly share code, notes, and snippets.

@kristopher
Created April 24, 2009 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristopher/100868 to your computer and use it in GitHub Desktop.
Save kristopher/100868 to your computer and use it in GitHub Desktop.
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