DEFINITIONS
This source file includes following functions.
1 #! /usr/local/bin/ruby
2
3 require "thread"
4 require "observer"
5
6 class Tick
7 include Observable
8 def initialize
9 Thread.start do
10 loop do
11 sleep 0.999
12 now = Time.now
13 changed
14 notify_observers(now.hour, now.min, now.sec)
15 end
16 end
17 end
18 end
19
20 class Clock
21 def initialize(tick)
22 @tick = tick
23 @tick.add_observer(self)
24 end
25 def update(h, m, s)
26 printf "\e[8D%02d:%02d:%02d", h, m, s
27 STDOUT.flush
28 end
29 end
30
31 clock = Clock.new(Tick.new)
32 sleep