Refactor Dispatcher
This commit is contained in:
@@ -3,21 +3,20 @@ module Uh
|
||||
class Dispatcher
|
||||
attr_reader :hooks
|
||||
|
||||
def initialize hooks = Hash.new
|
||||
@hooks = hooks
|
||||
def initialize
|
||||
@hooks = Hash.new { |h, k| h[k] = [] }
|
||||
end
|
||||
|
||||
def [] *key
|
||||
@hooks[translate_key key] or []
|
||||
@hooks[translate_key key]
|
||||
end
|
||||
|
||||
def on *key, &block
|
||||
@hooks[translate_key key] ||= []
|
||||
@hooks[translate_key key] << block
|
||||
end
|
||||
|
||||
def emit *key
|
||||
@hooks[translate_key key].tap { |o| o.each { |e| e.call } if o }
|
||||
@hooks[translate_key key].each { |e| e.call }
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user