Sha256: cae10b15b0e17933511dc8fd5f442f4ffc0e24dd90dc650462654b62c8535979

Contents?: true

Size: 540 Bytes

Versions: 11

Compression:

Stored size: 540 Bytes

Contents

module Xot


  module Hookable

    def hook(name, &block)
      singleton_class.__send__ :define_method, name, &block
      self
    end

    def on(name, &block)
      hook name do |*a, &b|
        block.call(*a, &b)
      end
    end

    def before(name, &block)
      hook name do |*a, &b|
        super(*a, &b) unless block.call(*a, &b) == :skip
      end
    end

    def after(name, &block)
      hook name do |*a, &b|
        ret = super(*a, &b)
        block.call(*a, &b)
        ret
      end
    end

  end# Hookable


end# Xot

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
xot-0.3 lib/xot/hookable.rb
xot-0.2.1 lib/xot/hookable.rb
xot-0.2 lib/xot/hookable.rb
xot-0.1.42 lib/xot/hookable.rb
xot-0.1.41 lib/xot/hookable.rb
xot-0.1.40 lib/xot/hookable.rb
xot-0.1.39 lib/xot/hookable.rb
xot-0.1.38 lib/xot/hookable.rb
xot-0.1.37 lib/xot/hookable.rb
xot-0.1.36 lib/xot/hookable.rb
xot-0.1.35 lib/xot/hookable.rb