Skip to content

Instantly share code, notes, and snippets.

@kopylovvlad
Last active April 20, 2019 09:10
Show Gist options
  • Save kopylovvlad/4f6878a5cba4812dac09437cc8671538 to your computer and use it in GitHub Desktop.
Save kopylovvlad/4f6878a5cba4812dac09437cc8671538 to your computer and use it in GitHub Desktop.
require_relative './event_emitter_core'
class EventEmitter
include EventEmitterCore
end
event_emitter = EventEmitter.new
# the code should be executed when event will be triggered
ring_bell = lambda do |event_name, object|
puts 'ring ring ring'
end
# create an event 'doorOpen'
event_emitter.on(:doorOpen)
# and subscribe code to event
event_emitter.subscribe(:doorOpen, ring_bell)
# to trigger event
event_emitter.emit(:doorOpen)
# 'ring ring ring'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment