Module: Voicemeeter::Events::Director
- Included in:
- Base
- Defined in:
- lib/voicemeeter/event.rb
Instance Method Summary collapse
- #deregister(cbs) ⇒ Object
- #fire(event) ⇒ Object
- #observers ⇒ Object
- #on(event, method = nil, &block) ⇒ Object
- #register(cbs) ⇒ Object
Instance Method Details
#deregister(cbs) ⇒ Object
17 18 19 20 |
# File 'lib/voicemeeter/event.rb', line 17 def deregister(cbs) cbs = Array(cbs) unless cbs.respond_to? :each cbs.each { |cb| observers[cb.name[3..].to_sym]&.reject! { |o| cbs.include? o } } end |
#fire(event) ⇒ Object
22 23 24 |
# File 'lib/voicemeeter/event.rb', line 22 def fire(event) observers[event]&.each { |block| block.call } end |
#observers ⇒ Object
4 5 6 |
# File 'lib/voicemeeter/event.rb', line 4 def observers @observers ||= {} end |
#on(event, method = nil, &block) ⇒ Object
8 9 10 |
# File 'lib/voicemeeter/event.rb', line 8 def on(event, method = nil, &block) (observers[event] ||= []) << (block || method) end |
#register(cbs) ⇒ Object
12 13 14 15 |
# File 'lib/voicemeeter/event.rb', line 12 def register(cbs) cbs = Array(cbs) unless cbs.respond_to? :each cbs.each { |cb| on(cb.name[3..].to_sym, cb) } end |