Module: Perennial::Dispatchable
- Defined in:
- lib/perennial/dispatchable.rb
Overview
Perennial::Dispatchable
A Generic mixin which lets you define an object Which accepts handlers which can have arbitrary events dispatched.
Usage
class X
include Perennial::Dispatchable
self.handlers << SomeHandler.new
end
X.new.dispatch(:name, {:args => "Values"})
Will first check if SomeHandler#handle_name exists, calling handle_name(=> “Values”) if it does, otherwise calling SomeHandler#handle(:name, => “Values”)
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Class Method Details
.handler_mapping ⇒ Object
20 21 22 |
# File 'lib/perennial/dispatchable.rb', line 20 def self.handler_mapping @@handler_mapping ||= Hash.new { |h,k| h[k] = [] } end |
.included(parent) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/perennial/dispatchable.rb', line 28 def self.included(parent) parent.class_eval do include InstanceMethods extend ClassMethods end end |