diff options
Diffstat (limited to 'jni/ruby/sample/observ.rb')
-rw-r--r-- | jni/ruby/sample/observ.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/jni/ruby/sample/observ.rb b/jni/ruby/sample/observ.rb new file mode 100644 index 0000000..061e3c6 --- /dev/null +++ b/jni/ruby/sample/observ.rb @@ -0,0 +1,32 @@ +#! /usr/local/bin/ruby + +require "thread" +require "observer" + +class Tick + include Observable + def initialize + Thread.start do + loop do + sleep 0.999 + now = Time.now + changed + notify_observers(now.hour, now.min, now.sec) + end + end + end +end + +class Clock + def initialize(tick) + @tick = tick + @tick.add_observer(self) + end + def update(h, m, s) + printf "\e[8D%02d:%02d:%02d", h, m, s + STDOUT.flush + end +end + +clock = Clock.new(Tick.new) +sleep |