Skip to content

Instantly share code, notes, and snippets.

@sarahhodne
Created April 9, 2010 11:15
Show Gist options
  • Save sarahhodne/361061 to your computer and use it in GitHub Desktop.
Save sarahhodne/361061 to your computer and use it in GitHub Desktop.
class Hook
def self.hooks
@hooks ||= []
end
def initialize(event, &callback)
# Add the hook to the list of hooks
Hook.hooks << {:event => event, :callback => callback}
end
end
# This is only a shortcut
def on(*args)
return Hook.new(*args)
end
def fireevent(event, arguments)
Hook.hooks.each { |hook|
if hook[:event] == event
hook[:callback].call(arguments)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment