class Uh::WM::Dispatcher

Attributes

hooks[R]

Public Class Methods

new() click to toggle source
# File lib/uh/wm/dispatcher.rb, line 6
def initialize
  @hooks = Hash.new { |h, k| h[k] = [] }
end

Public Instance Methods

[](*key) click to toggle source
# File lib/uh/wm/dispatcher.rb, line 10
def [] *key
  @hooks[translate_key key]
end
emit(*key, args: []) click to toggle source
# 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) click to toggle source
# File lib/uh/wm/dispatcher.rb, line 14
def on *key, &block
  @hooks[translate_key key] << block
end

Private Instance Methods

translate_key(key) click to toggle source
# File lib/uh/wm/dispatcher.rb, line 26
def translate_key key
  key.one? ? key[0] : key
end