uh-wm/lib/uh/wm/dispatcher.rb
2015-04-09 00:30:12 +00:00

28 lines
435 B
Ruby

module Uh
module WM
class Dispatcher
attr_reader :hooks
def initialize hooks = Hash.new
@hooks = hooks
end
def [] *key
@hooks[translate_key key] or []
end
def on *key, &block
@hooks[translate_key key] ||= []
@hooks[translate_key key] << block
end
private
def translate_key key
key.one? ? key[0] : key
end
end
end
end