77件ヒット
[1-77件を表示]
(0.022秒)
キーワード
- ASN1 (11)
- Forwardable (11)
- MonitorMixin (11)
-
Mutex
_ m (11) - Observable (11)
- SingleForwardable (11)
- Singleton (11)
検索結果
-
OpenSSL
:: ASN1 (55.0) -
ASN.1(Abstract Syntax Notation One) のデータを取り扱うためのモジュールです。
...て数種類定義されています。
このリファレンスで言及されている DER 形式も
このエンコード形式の一種です。
=== 概要
このモジュールにおいて、
ASN.1 のデータ型は OpenSSL::ASN1::ASN1Data および
そのサブクラスにマップされて......00 @tag=12, @value="foobar", @tagging=nil, @tag_class=:UNIVERSAL>
OpenSSL::ASN1.decode(y.to_der)
# => #<OpenSSL::ASN1::Sequence:0x000000027c47d0 @tag=16, @value=[#<OpenSSL::ASN1::Boolean:0x000000027c4898 @tag=1, @value=true, @tagging=nil, @tag_class=:UNIVERSAL>, #<OpenSSL::ASN1::Integer:0x000000......gging=nil, @tag_class=:UNIVERSAL>], @tagging=nil, @tag_class=:UNIVERSAL>
OpenSSL::ASN1.decode(z.to_der)
# => #<OpenSSL::ASN1::ASN1Data:0x000000027bc918 @tag=2, @value=[#<OpenSSL::ASN1::Boolean:0x000000027bc968 @tag=1, @value=false, @tagging=nil, @tag_class=:UNIVERSAL>], @tag_class=:APPLICATION>... -
Observable (43.0)
-
Observer パターンを提供するモジュールです。
...す)。
Observable#notify_observers の引数は
そのままオブザーバの update メソッドに渡されます。
=== サンプルコード
require "observer"
class Ticker ### Periodically fetch a stock price.
include Observable
def initialize(symbol)
@symbol = s......bservers(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.
def initial......t
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(time, price)... -
MonitorMixin (19.0)
-
スレッドの同期機構としてのモニター機能を提供するモジュールです。
...ター機能を提供するモジュールです。
クラスに Module#include したり、オブジェクトに
Object#extend したりすることでそのクラス/オブジェクトに
モニタ機能を追加します。
=== 例
//emlist[消費者、生産者問題の例][ruby]{
require 'mo......追加)
empty_cond.signal # 配列に要素が追加されたことを条件変数を通して通知
end # ここでロックを開放
end
//}
=== 初期化
MonitorMixin は初期化される必要があります。
上の例のように Object#extend を使って利用する場合は
自動......数を受け付けないので
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
}
e... -
Singleton (19.0)
-
Singleton パターンを提供するモジュールです。
...す。
=== サンプルコード
require 'singleton'
class SomeSingletonClass
include Singleton
#....
end
a = SomeSingletonClass.instance
b = SomeSingletonClass.instance # a and b are same object
p [a,b] # => [#<SomeSingletonClass:0x0000562e6e18ddd0>, #<SomeSingletonClass:0x00......00562e6e18ddd0>]
a = SomeSingletonClass.new # => NoMethodError (private method `new' called for SomeSingletonClass:Class)... -
Forwardable (13.0)
-
クラスに対し、メソッドの委譲機能を定義するモジュールです。
...ソッドの委譲機能を定義するモジュールです。
=== 使い方
クラスに対して Object#extend して使います。Module#include でないところに注意して下さい。
例:
require 'forwardable'
class Foo
extend Forwardable
def_delegators("@out", "pri... -
Mutex
_ m (13.0) -
スレッド同期機構である Mutex のモジュール版です。クラスに Module#include することでそのクラスに Mutex 機能を持たせることができます。 また、普通のオブジェクトを Object#extend により Mutex にする事ができます。
...スレッド同期機構である Mutex のモジュール版です。クラスに
Module#include することでそのクラスに Mutex 機能を持たせることができます。
また、普通のオブジェクトを Object#extend により Mutex にする事ができます。
このモジ......?, Mutex_m#try_lock, Mutex_m#unlock)
はモジュールにincludeした場合には定義されません。
1991
=== 例
クラスに Module#include する例
require "mutex_m"
class Foo
include Mutex_m
...
end
obj = Foo.new
obj.synchronize do
# 危険領域(critical section......スレッド同期機構である Thread::Mutex のモジュール版です。クラスに
Module#include することでそのクラスに Mutex 機能を持たせることができます。
また、普通のオブジェクトを Object#extend により Mutex にする事ができます。
この... -
SingleForwardable (13.0)
-
オブジェクトに対し、メソッドの委譲機能を定義するモジュールです。
...オブジェクトに対し、メソッドの委譲機能を定義するモジュールです。
=== 使い方
オブジェクトに対して extend して使います。
例:
require 'forwardable'
g = Goo.new
g.extend SingleForwardable
g.def_delegator("@out", :puts)
g.puts ...
また......スやモジュールに対して以下のようにする事もできます。
require 'forwardable'
class Implementation
def self.service
puts "serviced!"
end
end
module Facade
extend SingleForwardable
def_delegator :Implementation, :service
end
Facade.service...