Module: Broadcasting

Defined in:
lib/broadcast-objects.rb

Overview

Basic module that implements the methods for subscribing and sending broadcasts. functionality for dealing with recieved broadcasts should be implemented by individual classes

Instance Method Summary collapse

Instance Method Details

#send(channel, data) ⇒ Object

send message to all objects that subscribed to channel, with data.



26
27
28
# File 'lib/broadcast-objects.rb', line 26

def send(channel, data)
	channel.broadcast data
end

#subscribe(channel, methSymbol) ⇒ Object

Subscribe to channel. While subscribed, will recieve message whenever another objects sends one on that channel. methSymbol should be a symbol or string corresponding to the method with which to recieve messaged from that channel.



21
22
23
24
# File 'lib/broadcast-objects.rb', line 21

def subscribe(channel, methSymbol)
	channel.subscribers.push self
	channel.methods.push self.method(methSymbol)
end