Class: KXI::Application::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/kxi/application/event.rb

Overview

Event handler

Instance Method Summary collapse

Constructor Details

#initializeEvent

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

Yields:

  • (sender, *args)

    Action block of hook

Yield Parameters:

  • sender (Object)

    Invoker of event

  • args (Array<Object, nil>)

    Arguments of invocation

Returns:

  • (Number)

    Id of hook



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

Parameters:

  • sender (Object)

    Invoker of event

  • args (Array<Object, nil>)

    Arguments of invocation



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

Parameters:

  • id (Number)

    Id of hook to remove



19
20
21
# File 'lib/kxi/application/event.rb', line 19

def remove(id)
	@hooks.delete_at(id)
end