Created
May 4, 2016 05:23
-
-
Save temirov/fe07201316c9112306e51291496b83a3 to your computer and use it in GitHub Desktop.
Quick PubSub implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bus | |
def subscribers | |
@subscribers ||= [] | |
end | |
def publish(*args) | |
subscribers.each do |subscriber| | |
subscriber.sub(*args) | |
end | |
end | |
def subscribe(subscriber) | |
raise unless subscriber.respond_to? :sub | |
@subscribers << subscriber | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment