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)

Instance Method Details

- (Object) off(event, &blk)

When `event` is triggered, do not call the given block any more



15
16
17
18
# File 'motion/reactor/eventable.rb', line 15

def off(event, &blk)
  __events__[event].delete_if { |b| b == blk }
  blk
end

- (Object) on(event, &blk)

When `event` is triggered the block will execute and be passed the arguments that are passed to `trigger`.



9
10
11
# File 'motion/reactor/eventable.rb', line 9

def on(event, &blk)
  __events__[event].push blk
end

- (Object) trigger(event, *args)

Trigger an event



21
22
23
24
25
26
# File 'motion/reactor/eventable.rb', line 21

def trigger(event, *args)
  blks = __events__[event].clone
  blks.map do |blk|
    blk.call(*args)
  end
end