Skip to content

Instantly share code, notes, and snippets.

@Burgestrand
Created September 21, 2011 16:46
Show Gist options
  • Save Burgestrand/1232614 to your computer and use it in GitHub Desktop.
Save Burgestrand/1232614 to your computer and use it in GitHub Desktop.
Method locator and ancestral heritage
require 'method_locator'
class A
def moo
"A"
end
end
class B < A
def moo
"B"
end
end
b = B.new
methods = b.methods_for(:moo).map do |method|
[method.owner, method.bind(b)]
end
methods = Hash[methods]
# Now ain’t this cool?
p methods[A].call
p methods[B].call
@Burgestrand
Copy link
Author

Might be worth noting this code uses the method_locator gem: https://github.com/ryanlecompte/method_locator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment