Created
July 16, 2012 08:38
-
-
Save eriksk/3121568 to your computer and use it in GitHub Desktop.
Events in Ruby
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
# an array of lambdas | |
listeners = [] | |
# just some function that prints text | |
def callback_puts text | |
puts text | |
end | |
# add some listeners | |
listeners.push lambda{ callback_puts("Hello") } | |
listeners.push lambda{ callback_puts("World") } | |
# some event kicked in, so call the listeners | |
listeners.each do |listener| | |
listener.call() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment