11件ヒット
[1-11件を表示]
(0.057秒)
ライブラリ
- observer (11)
検索結果
先頭1件
-
Observable (38061.0)
-
Observer パターンを提供するモジュールです。
...ターンを提供するモジュールです。
Mix-in により Observer パターンを提供します。
Observable モジュールを include したクラスは
Observable#changed メソッドにより更新フラグを立て、
Observable#notify_observers が呼び出されると
更新フ......ッドを呼び出す)。
Observable#notify_observers の引数は
そのままオブザーバの update メソッドに渡されます。
=== サンプルコード
require "observer"
class Ticker ### Periodically fetch a stock price.
include Observable
def initialize(symbol)......# notify observers
last_price = price
notify_observers(Time.now, price)
end
sleep 1
end
end
end
class Price ### A mock class to fetch a stock price (60 - 140).
def self.fetch(symbol)
60 + rand(80)
end
end
class Warner...