Created
October 8, 2013 16:01
-
-
Save flash-gordon/6887013 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 Foo | |
def self.method_added(method_name) | |
super | |
create_wrapper_for(method_name) | |
end | |
def self.create_wrapper_for(method) | |
wrap_module.class_eval <<-RUBY | |
def #{method}(*) | |
p '#{method} called!' | |
super | |
end | |
RUBY | |
end | |
def self.wrap_module | |
@wrap_module ||= begin | |
mod = Module.new | |
prepend mod | |
mod | |
end | |
end | |
end | |
class Bar < Foo | |
def vc_name | |
'Hello' | |
end | |
end | |
class Baz < Bar | |
def vc_code | |
'world' | |
end | |
end | |
Bar.new.vc_name | |
Baz.new.vc_name | |
Baz.new.vc_code | |
# "vc_name called!" | |
# "vc_name called!" | |
# "vc_code called!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment