Sha256: f8cc01ac52a6e207970192cb814b7a28ea5a11ec5d1886043bc3353624caa900

Contents?: true

Size: 587 Bytes

Versions: 16

Compression:

Stored size: 587 Bytes

Contents

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


module Xot


  module Hookable

    def hook (name, &block)
      c = class << self; self; end
      c.__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

16 entries across 16 versions & 1 rubygems

Version Path
xot-0.1.21 lib/xot/hookable.rb
xot-0.1.20 lib/xot/hookable.rb
xot-0.1.19 lib/xot/hookable.rb
xot-0.1.16 lib/xot/hookable.rb
xot-0.1.15 lib/xot/hookable.rb
xot-0.1.14 lib/xot/hookable.rb
xot-0.1.13 lib/xot/hookable.rb
xot-0.1.12 lib/xot/hookable.rb
xot-0.1.11 lib/xot/hookable.rb
xot-0.1.10 lib/xot/hookable.rb
xot-0.1.9 lib/xot/hookable.rb
xot-0.1.8 lib/xot/hookable.rb
xot-0.1.7 lib/xot/hookable.rb
xot-0.1.6 lib/xot/hookable.rb
xot-0.1.5 lib/xot/hookable.rb
xot-0.1.4 lib/xot/hookable.rb