Class: Uh::WM::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/uh/wm/dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDispatcher

Returns a new instance of Dispatcher.



6
7
8
# File 'lib/uh/wm/dispatcher.rb', line 6

def initialize
  @hooks = Hash.new { |h, k| h[k] = [] }
end

Instance Attribute Details

#hooksObject (readonly)

Returns the value of attribute hooks.



4
5
6
# File 'lib/uh/wm/dispatcher.rb', line 4

def hooks
  @hooks
end

Instance Method Details

#[](*key) ⇒ Object



10
11
12
# File 'lib/uh/wm/dispatcher.rb', line 10

def [] *key
  @hooks[translate_key key]
end

#emit(*key, args: []) ⇒ Object



18
19
20
21
22
# File 'lib/uh/wm/dispatcher.rb', line 18

def emit *key, args: []
  value = nil
  @hooks[translate_key key].each { |e| value = e.call *args }
  value
end

#on(*key, &block) ⇒ Object



14
15
16
# File 'lib/uh/wm/dispatcher.rb', line 14

def on *key, &block
  @hooks[translate_key key] << block
end