ruby/trema/timers.rb in trema-0.2.5 vs ruby/trema/timers.rb in trema-0.2.6

- old
+ new

@@ -26,21 +26,21 @@ module TimerMethods lambda { timer_event_handlers = {} - - + + Kernel.send :define_method, :add_timer do | handler, interval, event_type | timer_event_handlers[ handler ] = { :interval => interval, :rest => interval, :event_type => event_type } end - - + + Kernel.send :define_method, :fire_event do timer_event_handlers.each do | handler, data | data[ :rest ] -= 1 if data[ :rest ] <= 0 __send__ handler @@ -49,41 +49,41 @@ end timer_event_handlers.delete_if do | handler, data | data[ :rest ] <= 0 && data[ :event_type ] == :oneshot end end - - + + Kernel.send :define_method, :delete_timer do | handler | timer_event_handlers.delete end }.call - + def add_timer_event handler, interval, event_type add_timer handler, interval, event_type end alias_method :timer_event, :add_timer_event - + def delete_timer_event handler - delete_timer handler + delete_timer handler end - + # shortcut methods def add_periodic_timer_event handler, interval add_timer_event handler, interval, :periodic end alias_method :periodic_timer_event, :add_periodic_timer_event - + def add_oneshot_timer_event handler, interval add_timer_event handler, interval, :oneshot end alias_method :oneshot_timer_event, :add_oneshot_timer_event - - + + def handle_timer_event fire_event end end end