Created
October 7, 2015 02:20
-
-
Save paulodiniz/39698ac1fe5f62e3180e 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
module Mst | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def before(method_name) | |
m = instance_method(method_name) | |
define_method method_name do |*args, &block| | |
yield | |
m.bind(self).(*args, &block) | |
end | |
end | |
end | |
end | |
class Foo | |
include Mst | |
def test | |
puts "test" | |
end | |
before :test do | |
puts "before" | |
end | |
end | |
Foo.new.test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment