Skip to content

Instantly share code, notes, and snippets.

@jihao
Created December 15, 2011 09:05
Show Gist options
  • Save jihao/1480438 to your computer and use it in GitHub Desktop.
Save jihao/1480438 to your computer and use it in GitHub Desktop.
ruby.observer.rb
require "observer"
class Tick
include Observable
def tick
loop do
now = Time.now
changed
notify_observers(now.hour, now.min, now.sec)
sleep 1.0 - Time.now.usec / 1000000.0
end
end
end
class TextClock
def update(h,m,s)
printf "%02d:%02d:%02d \n", h, m, s
STDOUT.flush
end
end
tick = Tick.new
tick.add_observer(TextClock.new)
tick.tick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment