class Nanoc::Core::LazyValue
Holds a value that might be generated lazily.
Public Class Methods
new(value_or_proc)
click to toggle source
Takes a value or a proc to generate the value
# File lib/nanoc/core/lazy_value.rb, line 10 def initialize(value_or_proc) @value = { raw: value_or_proc } end
Public Instance Methods
freeze()
click to toggle source
Calls superclass method
# File lib/nanoc/core/lazy_value.rb, line 31 def freeze super @value.__nanoc_freeze_recursively unless @value[:raw] self end
map() { |value| ... }
click to toggle source
Returns a new lazy value that will apply the given transformation when the value is requested.
# File lib/nanoc/core/lazy_value.rb, line 26 def map self.class.new(-> { yield(value) }) end
value()
click to toggle source
Returns the value, generated when needed
# File lib/nanoc/core/lazy_value.rb, line 15 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