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
21 22 23 24 25 26 27 |
# File 'lib/xot/hookable.rb', line 21 def after(name, &block) hook name do |*a, **k, &b| ret = super(*a, **k, &b) block.call(*a, **k, &b) ret end end |
#before(name, &block) ⇒ Object
15 16 17 18 19 |
# File 'lib/xot/hookable.rb', line 15 def before(name, &block) hook name do |*a, **k, &b| super(*a, **k, &b) unless block.call(*a, **k, &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 |
# File 'lib/xot/hookable.rb', line 11 def on(name, &block) hook "on_#{name}", &block end |