Skip to content

Instantly share code, notes, and snippets.

@kerkerj
Created February 28, 2016 06:41
Show Gist options
  • Save kerkerj/b1f6102754e769843bdb to your computer and use it in GitHub Desktop.
Save kerkerj/b1f6102754e769843bdb to your computer and use it in GitHub Desktop.
# example for observer in Ruby
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 "\e[8D%02d:%02d:%02d", 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