Created
July 27, 2011 20:45
-
-
Save pigoz/1110334 to your computer and use it in GitHub Desktop.
method extensions through modules instead of alias_method_chain
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 TheFoo | |
module Base | |
def initialize | |
@foo = "foo" | |
end | |
def foo | |
@foo = "baz" | |
end | |
end | |
include Base | |
end | |
module AroundFilter | |
def foo | |
puts @foo | |
super | |
puts @foo | |
end | |
end | |
TheFoo.send(:include, AroundFilter) | |
TheFoo.new.foo | |
module BeforeFilter | |
def foo | |
puts "before foo" | |
super | |
end | |
end | |
TheFoo.send(:include, BeforeFilter) | |
TheFoo.new.foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment