Permalink
Browse files

Added event cast

  • Loading branch information...
1 parent be47ac6 commit d6a2c4a8da941008fd3963df30dd88bab3d37974 Cyrus Hall committed Mar 30, 2007
Showing with 29 additions and 0 deletions.
  1. +29 −0 lib/gosim/event_cast.rb
View
@@ -0,0 +1,29 @@
+module GoSim
+module Data
+
+ class EventCast
+ include Singleton
+
+ def initialize
+ @event_handlers = {}
+ end
+
+ def publish(type, *args)
+ if @event_handlers.has_key?(type)
+ @event_handlers[type].each { |e| e.call(*args) }
+ end
+ end
+
+ def add_handler(type, method = nil, &block)
+ method = method || block
+
+ return if method.nil?
+
+ @event_handlers[type] ||= []
+ @event_handlers[type] << method
+ end
+ end
+
+end
+end
+

0 comments on commit d6a2c4a

Please sign in to comment.