22件ヒット
[1-22件を表示]
(0.092秒)
ライブラリ
- forwardable (11)
- singleton (11)
キーワード
- SingleForwardable (11)
- Singleton (11)
検索結果
-
SingleForwardable (18001.0)
-
オブジェクトに対し、メソッドの委譲機能を定義するモジュールです。
...quire 'forwardable'
g = Goo.new
g.extend SingleForwardable
g.def_delegator("@out", :puts)
g.puts ...
また、SingleForwardable はクラスやモジュールに対して以下のようにする事もできます。
require 'forwardable'
class Implementation
def self.service......"serviced!"
end
end
module Facade
extend SingleForwardable
def_delegator :Implementation, :service
end
Facade.service # => serviced!
もし Forwardable と SingleForwardable の両方を使いたい場合、
def_instance_delegator と def_single_delegator メソッドの方... -
Singleton (12001.0)
-
Singleton パターンを提供するモジュールです。
...Singleton パターンを提供するモジュールです。
Mix-in により singleton パターンを提供します。
Singleton モジュールを include することにより、クラスは
高々ひとつのインスタンスしか持たないことが保証されます。
Singleton を M......re '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' called for SomeSingletonClass:Class)...