Module: Multiton::MetaMethods

Includes:
Inclusive
Defined in:
lib/multiton.rb

Instance Method Summary collapse

Instance Method Details

#initialized?(*e, &b) ⇒ Boolean

Returns:

  • (Boolean)


230
231
232
# File 'lib/multiton.rb', line 230

def initialized?(*e, &b)
  multiton_instance.key?(multiton_id(*e, &b))
end

#instance(*e, &b) ⇒ Object Also known as: new



215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/multiton.rb', line 215

def instance(*e, &b)
  arg = multiton_id(*e, &b)
  multiton_instance.fetch(arg) do
    multiton_mutex[arg].synchronize do
      multiton_instance.fetch(arg) do
        val = multiton_instance[arg] = new!(*e, &b) #new(*e, &b)
        val.instance_variable_set(:@multiton_initializer, e, &b)
        multiton_mutex.initialized(arg)
        val
      end
    end
  end
end