Class: LibSL::EventManager

Inherits:
Object
  • Object
show all
Defined in:
lib/events.rb

Class Method Summary collapse

Class Method Details

.fire_event(type, *args) ⇒ Object

Fires an event that will be handled by registered handlers

Parameters:

  • type (Symbol)

    Event type

  • args (args)

    (optional) Arguments passed to the handlers



55
56
57
# File 'lib/events.rb', line 55

def self.fire_event(type, *args)
	handlers.each { |h| h.handle(type, *args) if h.accept?(type) }
end

.handlersObject



35
36
37
38
# File 'lib/events.rb', line 35

def self.handlers
	@@handlers ||= []
	@@handlers
end

.register_handler(handler) ⇒ Object

Register an event handler if it does not already exist

Parameters:



42
43
44
# File 'lib/events.rb', line 42

def self.register_handler(handler)
	handlers << handler unless handlers.include? handler
end

.remove_handler(handler) ⇒ Object

Removes an event handler

Parameters:



48
49
50
# File 'lib/events.rb', line 48

def self.remove_handler(handler)
	handlers.delete handler
end