Class: Channel
- Inherits:
-
Object
- Object
- Channel
- Defined in:
- lib/channel/channel.rb
Instance Method Summary collapse
- #dispose ⇒ Object
-
#initialize ⇒ Channel
constructor
A new instance of Channel.
- #publish(packet) ⇒ Object
- #subscribe(client) ⇒ Object
- #unsubscribe(client) ⇒ Object
Constructor Details
#initialize ⇒ Channel
Returns a new instance of Channel.
2 3 4 |
# File 'lib/channel/channel.rb', line 2 def initialize @clients = Array.new end |
Instance Method Details
#dispose ⇒ Object
5 6 |
# File 'lib/channel/channel.rb', line 5 def dispose end |
#publish(packet) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/channel/channel.rb', line 20 def publish(packet) freezed = packet.freeze @clients.each do |client| client.send_data freezed end end |
#subscribe(client) ⇒ Object
8 9 10 |
# File 'lib/channel/channel.rb', line 8 def subscribe(client) @clients.push client end |
#unsubscribe(client) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/channel/channel.rb', line 11 def unsubscribe(client) @clients.delete client if @clients.size == 0 return nil else return true end end |