Skip to content

Instantly share code, notes, and snippets.

@pigoz
Created July 27, 2011 20:45
Show Gist options
  • Save pigoz/1110334 to your computer and use it in GitHub Desktop.
Save pigoz/1110334 to your computer and use it in GitHub Desktop.
method extensions through modules instead of alias_method_chain
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