Module: Narou::Eventable::ClassMethods

Defined in:
lib/eventable.rb

Instance Method Summary collapse

Instance Method Details

#add_event_listener(event_name, &block) ⇒ Object

Raises:



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

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



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

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