Class: LibSL::EventHandler
- Inherits:
-
Object
- Object
- LibSL::EventHandler
- Defined in:
- lib/events.rb
Instance Attribute Summary collapse
-
#types ⇒ Object
Returns the value of attribute types.
Instance Method Summary collapse
-
#accept?(type) ⇒ Boolean
Check if this handler can handle one specific event.
-
#handle(type, *args) ⇒ Object
Handle the event.
-
#initialize(handler, type = :all) ⇒ EventHandler
constructor
New event handler.
Constructor Details
#initialize(handler, type = :all) ⇒ EventHandler
New event handler
9 10 11 12 |
# File 'lib/events.rb', line 9 def initialize(handler, type=:all) @handler = handler @types = [*type] end |
Instance Attribute Details
#types ⇒ Object
Returns the value of attribute types.
4 5 6 |
# File 'lib/events.rb', line 4 def types @types end |
Instance Method Details
#accept?(type) ⇒ Boolean
Check if this handler can handle one specific event
16 17 18 19 20 21 22 23 24 |
# File 'lib/events.rb', line 16 def accept?(type) if @types.include? :all return true elsif @types.include? type return true else return false end end |
#handle(type, *args) ⇒ Object
Handle the event
29 30 31 |
# File 'lib/events.rb', line 29 def handle(type, *args) @handler.call(type, *args) end |