Created
May 19, 2013 01:55
-
-
Save chrisallick/5606356 to your computer and use it in GitHub Desktop.
event registration and triggering 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
@@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