Module: Unity::Dependency

Defined in:
lib/unity/dependency.rb,
lib/unity/dependency/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
'1.0.1'

Instance Method Summary collapse

Instance Method Details

#__dependency_thread_instances__Hash<String, self>

Returns:

  • (Hash<String, self>)


10
11
12
# File 'lib/unity/dependency.rb', line 10

def __dependency_thread_instances__
  Thread.current[:__dependency_thread_instances__] ||= {}
end

#instanceself

Returns an instance of self attached to the current thread

Returns:

  • (self)


16
17
18
19
20
21
22
# File 'lib/unity/dependency.rb', line 16

def instance
  instances = __dependency_thread_instances__
  klass_name = self.name
  return instances[klass_name] if instances.key?(klass_name)

  instances[klass_name] = new
end