Created
June 9, 2011 14:45
-
-
Save eyston/1016863 to your computer and use it in GitHub Desktop.
Ruby Events? Maybe?
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 EventBus | |
def self.publish event args | |
@subscribers[event].each do |sub| | |
# whatever meta stuff sends event to method on object (handler) :p | |
end | |
end | |
def self.subscribe event, handler, method | |
@subscribers[event] = { :handler => handler, :method => method } | |
end | |
module EventHandler | |
def subscribe event, method=:handle | |
EventBus.subscribe event, self, method # self might be in the wrong context here, I'm ruby meta dumb | |
end | |
end | |
class CustomerPreferredHandler | |
include EventHandler | |
subscribe :customer_preferred_event | |
def handle customer_preferred_event_args | |
# wutevs | |
end | |
end | |
EventBus.send :customer_preferred_event, { :some => args } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment