Created
August 10, 2011 15:49
-
-
Save fcastellanos/1137232 to your computer and use it in GitHub Desktop.
Bingind and Unbinding methods
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 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