ライブラリ
キーワード
- ContextExtender (12)
- Extend (24)
- ExtendCommandBundle (12)
- Forwardable (12)
- MonitorMixin (12)
-
Mutex
_ m (12) - NKF (12)
- OCSP (12)
- Observable (12)
- Open3 (12)
- Readline (12)
- SingleForwardable (12)
- Singleton (12)
- Syslog (12)
検索結果
先頭5件
-
IRB
:: ContextExtender (6001.0) -
IRB::Context を拡張するためのモジュールです。
IRB::Context を拡張するためのモジュールです。 -
IRB
:: ExtendCommandBundle (6001.0) -
irb のコマンドを拡張するためのモジュールです。
irb のコマンドを拡張するためのモジュールです。 -
JSON
:: Ext :: Generator :: GeneratorMethods :: String :: Extend (6001.0) -
Alias of JSON::Generator::GeneratorMethods::String::Extend
...Alias of JSON::Generator::GeneratorMethods::String::Extend... -
JSON
:: Generator :: GeneratorMethods :: String :: Extend (6001.0) -
String に JSON で使用する特異メソッドを追加するためのモジュールです。
String に JSON で使用する特異メソッドを追加するためのモジュールです。 -
Observable (91.0)
-
Observer パターンを提供するモジュールです。
...observer"
class Ticker ### Periodically fetch a stock price.
include Observable
def initialize(symbol)
@symbol = symbol
end
def run
last_price = nil
loop do
price = Price.fetch(@symbol)
print "Current price: #{price}\n"
if 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 ### An abstract observer of Ticker objects.......imit = limit
ticker.add_observer(self)
end
end
class WarnLow < Warner
def update(time, price) # callback for observer
if price < @limit
print "--- #{time.to_s}: Price below #@limit: #{price}\n"
end
end
end
class WarnHigh < Warner
def update(t... -
MonitorMixin (49.0)
-
スレッドの同期機構としてのモニター機能を提供するモジュールです。
...。
クラスに Module#include したり、オブジェクトに
Object#extend したりすることでそのクラス/オブジェクトに
モニタ機能を追加します。
=== 例
//emlist[消費者、生産者問題の例][ruby]{
require 'monitor'
buf = []
buf.extend(MonitorMixin) # 配......行
end # ロックを開放
end
end
# producer
while line = ARGF.gets
buf.synchronize do # ロックする
buf.push(line) # 配列を変更(追加)
empty_cond.signal # 配列に要素が追加されたことを条件変数を通して通知
end # ここでロックを開放
end
/......。
上の例のように Object#extend を使って利用する場合は
自動的に初期化されます。
//emlist[extend する例][ruby]{
require 'monitor'
buf = []
buf.extend(MonitorMixin)
//}
しかし、MonitorMixin をクラス定義の際に Module#include を使って
利用する場... -
NKF (19.0)
-
nkf(Network Kanji code conversion Filter, https://osdn.net/projects/nkf/) を Ruby から使うためのモジュールです。
...t[例][ruby]{
#!/usr/local/bin/ruby
require 'nkf'
opt = ''
opt = ARGV.shift if ARGV[0][0] == ?-
while line = ARGF.gets
print NKF.nkf(opt, line)
end
//}
以下は、漢字コード判別コマンドの例です。
//emlist[例][ruby]{
#!/usr/local/bin/ruby
require 'nkf'
CODES = {
NKF::JIS......ift
str = open(file) {|io| io.gets(nil) }
printf "%-10s ", file
if str.nil?
puts "EMPTY"
else
puts CODES.fetch(NKF.guess(str))
end
end
//}
=== オプション文字列
-b 入力がバッファリングされる(デフォルト)
-u 入力がバッファリングされない... -
SingleForwardable (19.0)
-
オブジェクトに対し、メソッドの委譲機能を定義するモジュールです。
...ドの委譲機能を定義するモジュールです。
=== 使い方
オブジェクトに対して extend して使います。
例:
require 'forwardable'
g = Goo.new
g.extend SingleForwardable
g.def_delegator("@out", :puts)
g.puts ...
また、SingleForwardable はクラスやモ......require 'forwardable'
class Implementation
def self.service
puts "serviced!"
end
end
module Facade
extend SingleForwardable
def_delegator :Implementation, :service
end
Facade.service # => serviced!
もし Forwardable と SingleForwardable の両方を使い... -
Mutex
_ m (13.0) -
スレッド同期機構である Thread::Mutex のモジュール版です。クラスに Module#include することでそのクラスに Mutex 機能を持たせることができます。 また、普通のオブジェクトを Object#extend により Mutex にする事ができます。
...ド同期機構である Mutex のモジュール版です。クラスに
Module#include することでそのクラスに Mutex 機能を持たせることができます。
また、普通のオブジェクトを Object#extend により Mutex にする事ができます。
このモジュール......ラスに Module#include する例
require "mutex_m"
class Foo
include Mutex_m
...
end
obj = Foo.new
obj.synchronize do
# 危険領域(critical section)
...
end
オブジェクトに Object#extend する例
require "mutex_m"
obj = Object.new
obj.extend(Mutex_m)......機構である Thread::Mutex のモジュール版です。クラスに
Module#include することでそのクラスに Mutex 機能を持たせることができます。
また、普通のオブジェクトを Object#extend により Mutex にする事ができます。
このモジュールに...