Skip to content

Instantly share code, notes, and snippets.

@wycats
Forked from paulodiniz/gist:39698ac1fe5f62e3180e
Created October 7, 2015 06:28
Show Gist options
  • Save wycats/d16b1c64b9f88169ad1c to your computer and use it in GitHub Desktop.
Save wycats/d16b1c64b9f88169ad1c to your computer and use it in GitHub Desktop.

Revisions

  1. @paulodiniz paulodiniz created this gist Oct 7, 2015.
    31 changes: 31 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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