Class: Uh::WM::Dispatcher
- Inherits:
-
Object
- Object
- Uh::WM::Dispatcher
- Defined in:
- lib/uh/wm/dispatcher.rb
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
Instance Method Summary collapse
- #[](*key) ⇒ Object
- #emit(*key, args: []) ⇒ Object
-
#initialize ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #on(*key, &block) ⇒ Object
Constructor Details
#initialize ⇒ Dispatcher
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
#hooks ⇒ Object (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 |