Module: Narou::Eventable::ClassMethods

Defined in:
lib/eventable.rb

Instance Method Summary collapse

Instance Method Details

#add_event_listener(event_name, &block) ⇒ Object

Raises:



18
19
20
21
22
# File 'lib/eventable.rb', line 18

def add_event_listener(event_name, &block)
  raise NonBlockError unless block_given?
  stack = EVENTS_CONTAINER[self][event_name] ||= []
  stack.push(block)
end

#trigger_event(event_name, *argv) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/eventable.rb', line 24

def trigger_event(event_name, *argv)
  stack = EVENTS_CONTAINER[self][event_name]
  return unless stack
  stack.each do |block|
    block.call(*argv)
  end
end