33件ヒット
[1-33件を表示]
(0.098秒)
ライブラリ
- digest (11)
- forwardable (11)
- singleton (11)
キーワード
- Instance (11)
- SingleForwardable (11)
- Singleton (11)
検索結果
-
Digest
:: Instance (12001.0) -
-
Singleton (6019.0)
-
Singleton パターンを提供するモジュールです。
...ingleton パターンを提供するモジュールです。
Mix-in により singleton パターンを提供します。
Singleton モジュールを include することにより、クラスは
高々ひとつのインスタンスしか持たないことが保証されます。
Singleton を Mi......x-in したクラスの
クラスメソッド instance はその唯一のインスタンスを返します。
new は private メソッドに移され、外部から呼び出そうとするとエラーになります。
=== サンプルコード
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:0x0000562e6e18ddd0>]
a = SomeSingletonClass.new # => NoMethodError (private method `new... -
SingleForwardable (6007.0)
-
オブジェクトに対し、メソッドの委譲機能を定義するモジュールです。
...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 の両方を使いたい場合、
def_instance_delegator と def_single_delegator メソッ...