Created
March 6, 2012 22:43
-
-
Save jbarnette/1989514 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
module Watchable | |
def events | |
@events ||= Hash.new { |h,k| h[k] = [] } | |
end | |
def fire event, *args | |
events[event].each { |e| e[*args] } | |
end | |
def on event, &block | |
events[event] << block | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could update the gist and use it as a microgem :)