-
-
Save wycats/0a354a96d00d47fa4e04 to your computer and use it in GitHub Desktop.
This file contains 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 test | |
puts "test" | |
end | |
end | |
class Foo | |
prepend Module.new { | |
def test(*) | |
puts "before" | |
super | |
end | |
} | |
end |
This file contains 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
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