Class: Nanoc::Int::LazyValue Private
- Inherits:
-
Object
- Object
- Nanoc::Int::LazyValue
- Includes:
- ContractsSupport
- Defined in:
- lib/nanoc/base/entities/lazy_value.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Holds a value that might be generated lazily.
Instance Method Summary collapse
- #freeze ⇒ void private
-
#initialize(value_or_proc) ⇒ LazyValue
constructor
private
A new instance of LazyValue.
-
#map { ... } ⇒ Nanoc::Int::LazyValue
private
Returns a new lazy value that will apply the given transformation when the value is requested.
-
#value ⇒ Object
private
The value, generated when needed.
Methods included from ContractsSupport
Constructor Details
#initialize(value_or_proc) ⇒ LazyValue
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of LazyValue.
9 10 11 |
# File 'lib/nanoc/base/entities/lazy_value.rb', line 9 def initialize(value_or_proc) @value = { raw: value_or_proc } end |
Instance Method Details
#freeze ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
35 36 37 38 39 |
# File 'lib/nanoc/base/entities/lazy_value.rb', line 35 def freeze super @value.__nanoc_freeze_recursively unless @value[:raw] self end |
#map { ... } ⇒ Nanoc::Int::LazyValue
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new lazy value that will apply the given transformation when the value is requested.
29 30 31 |
# File 'lib/nanoc/base/entities/lazy_value.rb', line 29 def map Nanoc::Int::LazyValue.new(-> { yield(value) }) end |
#value ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The value, generated when needed.
14 15 16 17 18 19 20 21 |
# File 'lib/nanoc/base/entities/lazy_value.rb', line 14 def value if @value.key?(:raw) value = @value.delete(:raw) @value[:final] = value.respond_to?(:call) ? value.call : value @value.__nanoc_freeze_recursively if frozen? end @value[:final] end |