Skip to content

Instantly share code, notes, and snippets.

@temirov
Created May 4, 2016 05:23
Show Gist options
  • Save temirov/fe07201316c9112306e51291496b83a3 to your computer and use it in GitHub Desktop.
Save temirov/fe07201316c9112306e51291496b83a3 to your computer and use it in GitHub Desktop.
Quick PubSub implementation
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