Class: Channel
- Inherits:
-
Object
- Object
- Channel
- Defined in:
- lib/broadcast-objects.rb
Overview
Class for organizing broadcasts.
Instance Attribute Summary collapse
-
#methods ⇒ Object
Returns the value of attribute methods.
-
#subscribers ⇒ Object
Returns the value of attribute subscribers.
Instance Method Summary collapse
-
#broadcast(data) ⇒ Object
Called when a Broadcasting object sends a broadcast on this channel.
-
#initialize ⇒ Channel
constructor
A new instance of Channel.
Constructor Details
#initialize ⇒ Channel
Returns a new instance of Channel.
3 4 5 6 |
# File 'lib/broadcast-objects.rb', line 3 def initialize @subscribers = [] @methods = [] end |
Instance Attribute Details
#methods ⇒ Object
Returns the value of attribute methods.
15 16 17 |
# File 'lib/broadcast-objects.rb', line 15 def methods @methods end |
#subscribers ⇒ Object
Returns the value of attribute subscribers.
15 16 17 |
# File 'lib/broadcast-objects.rb', line 15 def subscribers @subscribers end |
Instance Method Details
#broadcast(data) ⇒ Object
Called when a Broadcasting object sends a broadcast on this channel. Calls the recieve method of all objects subscribing to this channel, passing the channel itself and the data sent as arguments
8 9 10 11 12 13 14 |
# File 'lib/broadcast-objects.rb', line 8 def broadcast data out = [] for i in methods out.push(i.call(data)) end return out end |