Class: Farce::Strict::LazyRef

Inherits:
Reference show all
Defined in:
lib/farce/strict/lazy_ref.rb

Overview

A Reference for a Lazy value. Delegates to the result after computing it on first access. Calling freeze resolves and freezes the target.

Examples:

reference = Farce::Strict::LazyRef.new { [:ready].freeze }
reference.first # => :ready

Instance Method Summary collapse

Methods inherited from Reference

[], deref, #duplicable?, #freeze, #frozen?, new, #respond_to?

Constructor Details

#initialize(factory) ⇒ LazyRef #initialize(self: nil) { ... } ⇒ LazyRef

Returns a new instance of LazyRef.

Overloads:

  • #initialize(factory) ⇒ LazyRef

    Parameters:

    • factory (Class, Proc, #call) —

      the factory for the lazy value, which must be shareable

  • #initialize(self: nil) { ... } ⇒ LazyRef

    Parameters:

    • self (BasicObject) (defaults to: nil) —

      the receiver to bind to the block, which must be shareable

    Yields:

    • computes the value on first access

    Yield Returns:

    • (BasicObject) —

      the computed result



24
# File 'lib/farce/strict/lazy_ref.rb', line 24

LazyRef = Reference[Farce::Strict::Lazy]

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Farce::Reference