* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / sample / observ.rb
blob72e5178b389805384f92c628d74e54be198d9909
1 #! /usr/local/bin/ruby
3 require "thread"
4 require "observer"
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
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
31 clock = Clock.new(Tick.new)
32 sleep