Created
February 28, 2016 06:41
-
-
Save kerkerj/b1f6102754e769843bdb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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