Class: KXI::Application::Event
- Inherits:
-
Object
- Object
- KXI::Application::Event
- Defined in:
- lib/kxi/application/event.rb
Overview
Event handler
Instance Method Summary collapse
-
#add {|sender, *args| ... } ⇒ Number
Adds hook to handler.
-
#fire(sender, *args) ⇒ Object
Invokes all hooks.
-
#initialize ⇒ Event
constructor
Instantiates the Event class.
-
#remove(id) ⇒ Object
Removes hook from handler.
Constructor Details
#initialize ⇒ Event
Instantiates the KXI::Application::Event class
24 25 26 |
# File 'lib/kxi/application/event.rb', line 24 def initialize @hooks = [] end |
Instance Method Details
#add {|sender, *args| ... } ⇒ Number
Adds hook to handler
12 13 14 15 |
# File 'lib/kxi/application/event.rb', line 12 def add(&block) @hooks.push(block) return @hooks.length - 1 end |
#fire(sender, *args) ⇒ Object
Invokes all hooks
31 32 33 |
# File 'lib/kxi/application/event.rb', line 31 def fire(sender, *args) @hooks.each { |h| h.call(sender, *args) } end |
#remove(id) ⇒ Object
Removes hook from handler
19 20 21 |
# File 'lib/kxi/application/event.rb', line 19 def remove(id) @hooks.delete_at(id) end |