Created
April 1, 2012 16:59
-
-
Save betawaffle/2277058 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
UnboundMethod.class_exec do | |
def to_proc | |
method = self | |
lambda { |*args, &block| method.bind(self).call(*args, &block) } | |
end | |
end |
This file contains hidden or 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
module MyModule | |
def some_method arg | |
[self, arg] | |
end | |
end | |
m = Object.new.extend(MyModule).method(:some_method) | |
'abc'.instance_exec('123', &m) # :( doesn't work! | |
# => [#<Object:0x...>, '123'] | |
'abc'.extend(MyModule).method(:some_method).call('123') | |
# => ['abc', '123'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allows you to do something like:
as long as obj has mod in it's ancestors