Class: Pry::Config::MemoizedValue Private

Inherits:
Object
  • Object
show all
Defined in:
lib/pry/config/memoized_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.

MemoizedValue is a Proc (block) wrapper. It is meant to be used as a configuration value. Subsequent ‘#call` calls return the same memoized result.

Examples:

num = 19
value = Pry::Config::MemoizedValue.new { num += 1 }
value.call # => 20
value.call # => 20
value.call # => 20

See Also:

Since:

  • v0.13.0

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ MemoizedValue

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 MemoizedValue.

Since:

  • v0.13.0



20
21
22
23
24
# File 'lib/pry/config/memoized_value.rb', line 20

def initialize(&block)
  @block = block
  @called = false
  @call = nil
end

Instance Method Details

#callObject

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.

Since:

  • v0.13.0



26
27
28
29
30
31
# File 'lib/pry/config/memoized_value.rb', line 26

def call
  return @call if @called

  @called = true
  @call = @block.call
end