Skip to content

Instantly share code, notes, and snippets.

@eriksk
Created July 16, 2012 08:38
Show Gist options
  • Save eriksk/3121568 to your computer and use it in GitHub Desktop.
Save eriksk/3121568 to your computer and use it in GitHub Desktop.
Events in Ruby
# 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