Module: Lotu::Eventful

Defined in:
lib/lotu/behaviors/eventful.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(instance) ⇒ Object



21
22
23
# File 'lib/lotu/behaviors/eventful.rb', line 21

def self.extended(instance)
  instance.init_behavior
end

Instance Method Details

#fire(event, *args) ⇒ Object



33
34
35
# File 'lib/lotu/behaviors/eventful.rb', line 33

def fire(event, *args)
  @events[event].call(*args) if @events[event]
end

#init_behaviorObject



25
26
27
# File 'lib/lotu/behaviors/eventful.rb', line 25

def init_behavior
  @events = {}
end

#on(event, &blk) ⇒ Object



29
30
31
# File 'lib/lotu/behaviors/eventful.rb', line 29

def on(event, &blk)
  @events[event] = blk
end