Class: PubSub
- Inherits:
-
Object
- Object
- PubSub
- Defined in:
- lib/polygon/pub_sub.rb
Instance Method Summary collapse
-
#initialize ⇒ PubSub
constructor
A new instance of PubSub.
- #pub(chan, data) ⇒ Object
- #sub(chan, clbk) ⇒ Object
Constructor Details
#initialize ⇒ PubSub
Returns a new instance of PubSub.
3 4 5 |
# File 'lib/polygon/pub_sub.rb', line 3 def initialize @subs = {} end |
Instance Method Details
#pub(chan, data) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/polygon/pub_sub.rb', line 12 def pub chan, data @subs[chan] ||= [] @subs[chan].each do |ch| ch.call(data) end end |
#sub(chan, clbk) ⇒ Object
7 8 9 10 |
# File 'lib/polygon/pub_sub.rb', line 7 def sub chan, clbk @subs[chan] ||= [] @subs[chan] << clbk end |