Skip to content

Instantly share code, notes, and snippets.

@wycats
Created October 7, 2015 06:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wycats/0a354a96d00d47fa4e04 to your computer and use it in GitHub Desktop.
Save wycats/0a354a96d00d47fa4e04 to your computer and use it in GitHub Desktop.
class Foo
def test
puts "test"
end
end
class Foo
prepend Module.new {
def test(*)
puts "before"
super
end
}
end
module Mst
def before(name, &advice)
mod = Module.new do
define_method(name) do |*args, &block|
advice.call
super(*args, &block)
end
end
prepend mod
end
end
class Foo
extend Mst
def test
puts "test"
end
before :test do
puts "before"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment