Class: SenroUsecaser::SingletonRegistration
- Inherits:
-
Object
- Object
- SenroUsecaser::SingletonRegistration
- Defined in:
- lib/senro_usecaser/container.rb
Overview
Wrapper for singleton registrations that caches the result
Instance Method Summary collapse
-
#call(container) ⇒ Object
: (Container) -> untyped.
-
#initialize(block) ⇒ SingletonRegistration
constructor
: (^(Container) -> untyped) -> void.
Constructor Details
#initialize(block) ⇒ SingletonRegistration
: (^(Container) -> untyped) -> void
9 10 11 12 13 |
# File 'lib/senro_usecaser/container.rb', line 9 def initialize(block) @block = block @resolved = false @value = nil end |
Instance Method Details
#call(container) ⇒ Object
: (Container) -> untyped
16 17 18 19 20 21 22 |
# File 'lib/senro_usecaser/container.rb', line 16 def call(container) unless @resolved @value = @block.call(container) @resolved = true end @value end |