Skip to content

Instantly share code, notes, and snippets.

@ileitch
Created February 17, 2012 21:40
Show Gist options
  • Select an option

  • Save ileitch/1855618 to your computer and use it in GitHub Desktop.

Select an option

Save ileitch/1855618 to your computer and use it in GitHub Desktop.
require 'delegate'
class Foo
def me
puts "meee"
end
end
foo = Foo.new
delegator = SimpleDelegator.new(foo)
m = delegator.method(:me)
p m
delegator.__setobj__([1,2,3])
m.call
# MRI: Note inspect says the method is defined on SimpleDelegator.
# #<Method: SimpleDelegator#me>
# trust.rb:14:in `call': undefined method `me' for [1, 2, 3]:SimpleDelegator (NoMethodError)
# from trust.rb:14:in `<main>'
# I can achieve the same looking #inspect in rbx with:
#
# cm = Rubinius.find_method(foo, :me)
# Method.new(delegator, cm[1], cm[0], :me) <-- Note receiver argument.
#
# However the call is still made to the compiled method, m[0].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment