Module: Xot::Hookable

Defined in:
lib/xot/hookable.rb

Instance Method Summary collapse

Instance Method Details

#after(name, &block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/xot/hookable.rb', line 27

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

#before(name, &block) ⇒ Object



21
22
23
24
25
# File 'lib/xot/hookable.rb', line 21

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

#hook(name, &block) ⇒ Object



9
10
11
12
13
# File 'lib/xot/hookable.rb', line 9

def hook (name, &block)
  c = class << self; self; end
  c.__send__ :define_method, name, &block
  self
end

#on(name, &block) ⇒ Object



15
16
17
18
19
# File 'lib/xot/hookable.rb', line 15

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