Created
December 22, 2008 14:55
-
-
Save banister/39007 to your computer and use it in GitHub Desktop.
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
class EventController | |
def initialize | |
@event_hash = {} | |
end | |
def register_listener(event_name, lsr) | |
@event_hash[event_name] ||= [] | |
@event_hash[event_name] << lsr | |
end | |
def method_missing(event_name, *args, &block) | |
raise NoMethodError, "No method called #{sym} registered." if !@event_hash.has_key?(event_name) | |
# @event_hash[event_name].each { |lsr| lsr.send(event_name, *args, &block) } | |
end | |
def unregister_listener(event_name, lsr) | |
@event_hash[event_name].delete(lsr) if @event_hash[event_name] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment