Module: Xot::Hookable
- Defined in:
- lib/xot/hookable.rb
Instance Method Summary collapse
- #after(name, &block) ⇒ Object
- #before(name, &block) ⇒ Object
- #hook(name, &block) ⇒ Object
- #on(name, &block) ⇒ Object
Instance Method Details
#after(name, &block) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/xot/hookable.rb', line 26 def after(name, &block) hook name do |*a, &b| ret = super(*a, &b) block.call(*a, &b) ret end end |
#before(name, &block) ⇒ Object
20 21 22 23 24 |
# File 'lib/xot/hookable.rb', line 20 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 |
# File 'lib/xot/hookable.rb', line 9 def hook(name, &block) singleton_class.__send__ :define_method, name, &block self end |
#on(name, &block) ⇒ Object
14 15 16 17 18 |
# File 'lib/xot/hookable.rb', line 14 def on(name, &block) hook name do |*a, &b| block.call(*a, &b) end end |