-
-
Save apeiros/234189 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
class Object | |
def chain_method(with_symbol, &new_method) | |
old_method = method with_symbol | |
eigenclass = class << self; self; end | |
eigenclass.class_eval do | |
define_method with_symbol do |*args| new_method[old_method, *args] end | |
end | |
end | |
end | |
def foo(arg) | |
print 'in foo: ', arg, "\n" | |
end | |
puts | |
foo 'first call' | |
chain_method :foo do |old_method, arg | | |
puts 'in first block_eval' | |
old_method.call arg | |
end | |
puts | |
foo 'second call' | |
chain_method :foo do |old_method, arg| | |
puts 'in second block_eval' | |
old_method.call arg | |
end | |
puts | |
foo 'third call' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment