Class: Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/broadcast-objects.rb

Overview

Class for organizing broadcasts.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChannel

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

#methodsObject

Returns the value of attribute methods.



15
16
17
# File 'lib/broadcast-objects.rb', line 15

def methods
  @methods
end

#subscribersObject

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