Skip to content

Instantly share code, notes, and snippets.

@ianbishop
Created March 24, 2011 22:35
Show Gist options
  • Save ianbishop/886038 to your computer and use it in GitHub Desktop.
Save ianbishop/886038 to your computer and use it in GitHub Desktop.
Revised repeater that uses send/respond_to? instead
class Repeater
@@subscribers = []
def subscribe(newSubscriber)
@@subscribers << newSubscriber
end
def broadcast(message)
@@subscribers.each { |subscriber|
subscriber.send(message[:command], message[:options]) if subscriber.respond_to? message[:command]
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment