Module: BubbleWrap::Reactor::Eventable
- Included in:
- PeriodicTimer, Timer
- Defined in:
- motion/reactor/eventable.rb
Overview
A simple mixin that adds events to your object.
Instance Method Summary collapse
-
#on(event, &blk) ⇒ Object
When ‘event` is triggered the block will execute and be passed the arguments that are passed to `trigger`.
-
#trigger(event, *args) ⇒ Object
Trigger an event.
Instance Method Details
#on(event, &blk) ⇒ Object
When ‘event` is triggered the block will execute and be passed the arguments that are passed to `trigger`.
9 10 11 12 |
# File 'motion/reactor/eventable.rb', line 9 def on(event, &blk) @events ||= Hash.new { |h,k| h[k] = [] } @events[event].push blk end |
#trigger(event, *args) ⇒ Object
Trigger an event
15 16 17 18 19 20 |
# File 'motion/reactor/eventable.rb', line 15 def trigger(event, *args) @events ||= Hash.new { |h,k| h[k] = [] } @events[event].map do |event| event.call(*args) end end |