Skip to content

Instantly share code, notes, and snippets.

@fcastellanos
Created August 10, 2011 15:49
Show Gist options
  • Save fcastellanos/1137232 to your computer and use it in GitHub Desktop.
Save fcastellanos/1137232 to your computer and use it in GitHub Desktop.
Bingind and Unbinding methods
class MyClass
def initialize(value)
@x = value
end
def my_method
@x
end
end
object = MyClass.new(1)
m = object.method :my_method
m.call # => 1
unbound = m.unbind
another_object = MyClass.new(2)
m = unbound.bind(another_object)
m.call # => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment