Skip to content

Instantly share code, notes, and snippets.

@brecert
Created April 10, 2018 18:54
Show Gist options
  • Save brecert/110850e630cf55e1428049ecb3ca20b9 to your computer and use it in GitHub Desktop.
Save brecert/110850e630cf55e1428049ecb3ca20b9 to your computer and use it in GitHub Desktop.
class EventEmitter
def initialize
@events = {
"blah" => []
}
end
def on(name, &handler)
@events[name] << handler
end
def emit(name, *args)
@events[name].each do |handler|
handler.call(*args)
end
end
end
events = EventEmitter.new()
events.on("blah") do |b|
puts b
end
events.emit("blah", 'hi')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment