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
23 24 25 26 27 28 29 |
# File 'lib/xot/hookable.rb', line 23 def after(name, &block) hook name do |*a, &b| ret = super(*a, &b) block.call(*a, &b) ret end end |
#before(name, &block) ⇒ Object
17 18 19 20 21 |
# File 'lib/xot/hookable.rb', line 17 def before(name, &block) hook name do |*a, &b| super(*a, &b) unless block.call(*a, &b) == :skip end end |
#hook(name, &block) ⇒ Object
6 7 8 9 |
# File 'lib/xot/hookable.rb', line 6 def hook(name, &block) singleton_class.__send__ :define_method, name, &block self end |
#on(name, &block) ⇒ Object
11 12 13 14 15 |
# File 'lib/xot/hookable.rb', line 11 def on(name, &block) hook name do |*a, &b| block.call(*a, &b) end end |