るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.154秒)
トップページ > クエリ:I[x] > クエリ:A[x] > クエリ:private[x] > 種類:モジュール[x]

別のキーワード

  1. _builtin to_i
  2. fiddle to_i
  3. matrix elements_to_i
  4. matrix i
  5. _builtin i

ライブラリ

検索結果

Singleton (6037.0)

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

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

Mix-in により singleton パターンを提供します。

Singleton モジュールを include することにより、クラスは
高々ひとつのインスタンスしか持たないことが保証されます。

Singleton を Mi...
...x-in したクラスの
クラスメソッド instance はその唯一のインスタンスを返します。

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

=== サンプルコード

require 'singleton'

class SomeSingletonClass...
...de 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...