Skip to content

Instantly share code, notes, and snippets.

@paulodiniz
Created October 7, 2015 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save paulodiniz/39698ac1fe5f62e3180e to your computer and use it in GitHub Desktop.
Save paulodiniz/39698ac1fe5f62e3180e to your computer and use it in GitHub Desktop.
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