るりまサーチ

最速Rubyリファレンスマニュアル検索!
77件ヒット [1-77件を表示] (0.057秒)
トップページ > クエリ:Class#new[x] > クエリ:extend[x] > クエリ:parameters[x] > 種類:モジュール[x]

別のキーワード

  1. << rexml::attribute#name
  2. add rexml::attribute#name
  3. handle_interrupt thread#raise
  4. service drb::extserv#stop_service
  5. inspect? irb::context#inspect_mode

ライブラリ

キーワード

検索結果

OpenSSL::ASN1 (97.0)

ASN.1(Abstract Syntax Notation One) のデータを取り扱うためのモジュールです。

...tring.new("foobar")
# 構造型のデータ
y = OpenSSL::ASN1::Sequence.new([OpenSSL::ASN1::Boolean.new(true),
OpenSSL::ASN1::Integer.new(-12)])
# APPLICATION タグクラスのタグ2番でタグ付けられたデータ
z = OpenSSL::ASN1::ASN1Data.new([Open...
...SSL::ASN1::Boolean.new(false)],
2, :APPLICATION)
# 上と同様のデータを OpenSSL::ASN1::Boolean.new の2番目以降の
# 引数で表現する
z2 = OpenSSL::ASN1::Boolean.new(false, 2, :EXPLICIT, :APPLICATION)
# IMPLICIT なタグ付けをする
u...
...= OpenSSL::ASN1::Boolean.new(false, 3, :IMPLICIT, :APPLICATION)

# to_der でエンコード
x.to_der # => "\f\x06foobar"
y.to_der # => "0\x06\x01\x01\xFF\x02\x01\xF4"
z.to_der # => "b\x03\x01\x01\x00"
z2.to_der # => "b\x03\x01\x01\x00" これは z.to_der と同じ
u.to_der # => "C\x...

Observable (55.0)

Observer パターンを提供するモジュールです。

...ify_observers の引数は
そのままオブザーバの update メソッドに渡されます。

=== サンプルコード
require "observer"

class
Ticker ### Periodically fetch a stock price.
include Observable

def initialize(symbol)
@symbol = symbol
end

def...
...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)...

Singleton (31.0)

Singleton パターンを提供するモジュールです。

...す。

new
は private メソッドに移され、外部から呼び出そうとするとエラーになります。

=== サンプルコード

require 'singleton'

class
SomeSingletonClass
include Singleton
#....
end

a = SomeSingletonClass.instance
b = SomeSingletonClass.instanc...
...e # a and b are same object
p [a,b] # => [#<SomeSingletonClass:0x0000562e6e18ddd0>, #<SomeSingletonClass:0x0000562e6e18ddd0>]
a = SomeSingletonClass.new # => NoMethodError (private method `new' called for SomeSingletonClass:Class)...

Mutex_m (19.0)

スレッド同期機構である 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 にする事ができます。

このモジュールに...

Forwardable (13.0)

クラスに対し、メソッドの委譲機能を定義するモジュールです。

...義するモジュールです。

=== 使い方

クラスに対して Object#extend して使います。Module#include でないところに注意して下さい。

例:

require 'forwardable'
class
Foo
extend
Forwardable

def_delegators("@out", "printf", "print")
def_delegat...
...ors(:@in, :gets)
def_delegator(:@contents, :[], "content_at")
end
f = Foo.new
f.printf ...
f.gets
f.content_at(1)...

絞り込み条件を変える

MonitorMixin (13.0)

スレッドの同期機構としてのモニター機能を提供するモジュールです。

...

クラスに Module#include したり、オブジェクトに
Object#extend したりすることでそのクラス/オブジェクトに
モニタ機能を追加します。

=== 例

//emlist[消費者、生産者問題の例][ruby]{
require 'monitor'

buf = []
buf.extend(MonitorMixin) # 配...
...列にモニタ機能を追加
empty_cond = buf.new_cond # 配列が空であるかないかを通知する条件変数

# consumer
Thread.start do
loop do
buf.synchronize do # ロックする
empty_cond.wait_while { buf.empty? } # 配列が空である間はロックを開放して待...
...す。
上の例のように Object#extend を使って利用する場合は
自動的に初期化されます。

//emlist[extend する例][ruby]{
require 'monitor'
buf = []
buf.extend(MonitorMixin)
//}

しかし、MonitorMixin をクラス定義の際に Module#include を使って
利用する...

SingleForwardable (13.0)

オブジェクトに対し、メソッドの委譲機能を定義するモジュールです。

... extend して使います。

例:

require 'forwardable'
g = Goo.new
g.extend SingleForwardable
g.def_delegator("@out", :puts)
g.puts ...

また、SingleForwardable はクラスやモジュールに対して以下のようにする事もできます。

require 'forwardable'
class
I...
...mplementation
def self.service
puts "serviced!"
end
end

module
Facade
extend
SingleForwardable
def_delegator :Implementation, :service
end

Facade.service # => serviced!

もし Forwardable と SingleForwardable の両方を使いたい場合、
def_instance_delegato...