Sha256: b8bf7127347fc32fd72d31ac62c7ec488f3f89e3392244fffd6e7166a62efdba

Contents?: true

Size: 566 Bytes

Versions: 9

Compression:

Stored size: 566 Bytes

Contents

# -*- coding: utf-8 -*-


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

9 entries across 9 versions & 1 rubygems

Version Path
xot-0.1.34 lib/xot/hookable.rb
xot-0.1.33 lib/xot/hookable.rb
xot-0.1.32 lib/xot/hookable.rb
xot-0.1.31 lib/xot/hookable.rb
xot-0.1.30 lib/xot/hookable.rb
xot-0.1.29 lib/xot/hookable.rb
xot-0.1.28 lib/xot/hookable.rb
xot-0.1.27 lib/xot/hookable.rb
xot-0.1.26 lib/xot/hookable.rb