Module: Marvin::Dispatchable::ClassMethods
- Defined in:
- lib/marvin/dispatchable.rb
Instance Method Summary collapse
-
#handlers ⇒ Object
Return an array of all registered handlers, stored in the class variable @@handlers.
-
#handlers=(new_value) ⇒ Object
Assigns a new array of handlers and assigns each.
-
#register_handler(handler) ⇒ Object
Appends a handler to the list of handlers for this object.
Instance Method Details
#handlers ⇒ Object
Return an array of all registered handlers, stored in the class variable @@handlers. Used inside the #handlers instance method as well as inside things such as register_handler.
80 81 82 |
# File 'lib/marvin/dispatchable.rb', line 80 def handlers @@handlers ||= [] end |
#handlers=(new_value) ⇒ Object
Assigns a new array of handlers and assigns each.
85 86 87 88 |
# File 'lib/marvin/dispatchable.rb', line 85 def handlers=(new_value) @@handlers = [] new_value.to_a.each { |h| register_handler h } end |
#register_handler(handler) ⇒ Object
Appends a handler to the list of handlers for this object. Handlers are called in the order they are registered.
92 93 94 |
# File 'lib/marvin/dispatchable.rb', line 92 def register_handler(handler) self.handlers << handler unless handler.nil? || !handler.respond_to?(:handle) end |