Skip to content

Instantly share code, notes, and snippets.

@banister
Created December 22, 2008 14:55
Show Gist options
  • Save banister/39007 to your computer and use it in GitHub Desktop.
Save banister/39007 to your computer and use it in GitHub Desktop.
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