24件ヒット
[1-24件を表示]
(0.023秒)
キーワード
- MonitorMixin (12)
- Observable (12)
検索結果
先頭2件
-
MonitorMixin (13.0)
-
スレッドの同期機構としてのモニター機能を提供するモジュールです。
...スレッドの同期機構としてのモニター機能を提供するモジュールです。
クラスに Module#include したり、オブジェクトに
Object#extend したりすることでそのクラス/オブジェクトに
モニタ機能を追加します。
=== 例
//emlist[消費......//emlist[extend する例][ruby]{
require 'monitor'
buf = []
buf.extend(MonitorMixin)
//}
しかし、MonitorMixin をクラス定義の際に Module#include を使って
利用する場合は、initialize メソッドで super() か super を呼んで、初期化する必要があります。......必要があります。
//emlist[include する例][ruby]{
require 'monitor'
class MyObject
include MonitorMixin
def initialize(val)
super()
@value = val
end
def to_s
synchronize {
@value.to_s
}
end
end
//}
以下も参考になります。
* 9384
* 9386... -
Observable (13.0)
-
Observer パターンを提供するモジュールです。
...if price < @limit
print "--- #{time.to_s}: Price below #@limit: #{price}\n"
end
end
end
class WarnHigh < Warner
def update(time, price) # callback for observer
if price > @limit
print "+++ #{time.to_s}: Price above #@limit: #{price}\n"
end...