Skip to content

Instantly share code, notes, and snippets.

@chrisallick
Created May 19, 2013 01:55
Show Gist options
  • Save chrisallick/5606356 to your computer and use it in GitHub Desktop.
Save chrisallick/5606356 to your computer and use it in GitHub Desktop.
event registration and triggering ruby
@@events = {}
def addEvent( event, type, function )
@@events[event] = {}
@@events[event]["type"] = type
@@events[event]["function"] = function
end
addEvent("compass", String, lambda{|msg|
puts "#{msg} world"
})
msg = "hello"
event = "compass"
type = String
if (@@events.has_key? event) and (msg.is_a? @@events[event]["type"])
@@events["compass"]["function"].call msg
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment