Methods
- _load
- initialized?
- instance
- multiton_id
- multiton_instance
- multiton_mutex
- new
- reinitialize
- singleton_method_added
Included Modules
Public Instance methods
[ show source ]
# File lib/facets/multiton.rb, line 230 def initialized?(*e, &b) multiton_instance.key?(multiton_id(*e, &b)) end
This method is also aliased as
new
[ show source ]
# File lib/facets/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
Alias for instance
Protected Instance methods
[ show source ]
# File lib/facets/multiton.rb, line 249 def _load(str) instance(*Marshal.load(str)) end
[ show source ]
# File lib/facets/multiton.rb, line 236 def multiton_instance @multiton_instance ||= Hash.new end
[ show source ]
# File lib/facets/multiton.rb, line 240 def multiton_mutex @multiton_mutex ||= InstanceMutex.new end
[ show source ]
# File lib/facets/multiton.rb, line 244 def reinitialize multiton_instance.clear multiton_mutex.clear end
Private Instance methods
Default method to to create a key to cache already constructed instances. In the use case MultitonClass.new(e), MultiClass.new(f) must be semantically equal if multiton_id(e).eql?(multiton_id(f)) evaluates to true.
[ show source ]
# File lib/facets/multiton.rb, line 259 def multiton_id(*e, &b) e end
[ show source ]
# File lib/facets/multiton.rb, line 263 def singleton_method_added(sym) super if (sym == :marshal_dump) & singleton_methods.include?('marshal_dump') raise TypeError, "Don't use marshal_dump - rely on _dump and _load instead" end end