Class: Decoding::Decoders::Lazy

Inherits:
Decoding::Decoder show all
Defined in:
lib/decoding/decoders/lazy.rb

Overview

A decoder that builds the decoder it delegates to on first use, rather than when it is created.

This is what makes recursive decoders possible: a decoder for a tree can refer to itself, since the reference is only resolved once there is a value to decode.

See Also:

Instance Method Summary collapse

Methods inherited from Decoding::Decoder

#failure, #to_decoder

Constructor Details

#initialize(&block) ⇒ Lazy

Returns a new instance of Lazy.

Yield Returns:



17
18
19
20
# File 'lib/decoding/decoders/lazy.rb', line 17

def initialize(&block)
  @block = block
  super()
end

Instance Method Details

#call(value) ⇒ Decoding::Result<a>

Parameters:

  • value (Object)

Returns:



24
# File 'lib/decoding/decoders/lazy.rb', line 24

def call(value) = decoder.call(value)