Module: Abstractivator::Event::ClassMethods
- Defined in:
- lib/abstractivator/event.rb
Instance Method Summary collapse
Instance Method Details
#event(*names) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/abstractivator/event.rb', line 7 def event(*names) names.each do |name| define_method("on_#{name}") do |&block| __event_hooks[name] << block proc { __event_hooks[name].delete(block) } end define_method("do_#{name}") do |*args, **kws, &block| __event_hooks[name].each do |hook| if hook.parameters.map(&:first).include?(:key) hook.call(*args, **kws, &block) else hook.call(*args, &block) end end end end end |