class KXI::Application::Event
Event
handler
Public Class Methods
new()
click to toggle source
Instantiates the {KXI::Application::Event} class
# File lib/kxi/application/event.rb, line 24 def initialize @hooks = [] end
Public Instance Methods
add(&block)
click to toggle source
Adds hook to handler @return [Number] Id of hook @yield [sender, *args] Action block of hook @yieldparam sender [Object] Invoker of event @yieldparam args [Array<Object, nil>] Arguments of invocation
# File lib/kxi/application/event.rb, line 12 def add(&block) @hooks.push(block) return @hooks.length - 1 end
fire(sender, *args)
click to toggle source
Invokes all hooks @param sender [Object] Invoker of event @param args [Array<Object, nil>] Arguments of invocation
# File lib/kxi/application/event.rb, line 31 def fire(sender, *args) @hooks.each { |h| h.call(sender, *args) } end
remove(id)
click to toggle source
Removes hook from handler @param id [Number] Id of hook to remove
# File lib/kxi/application/event.rb, line 19 def remove(id) @hooks.delete_at(id) end