Last active
April 20, 2019 09:10
-
-
Save kopylovvlad/4f6878a5cba4812dac09437cc8671538 to your computer and use it in GitHub Desktop.
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
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