summaryrefslogtreecommitdiff
path: root/lib/pry/config/lazy_value.rb
blob: 5df189156aac9ad7b8e521a7bdf0eedc40647437 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

class Pry
  class Config
    # LazyValue is a Proc (block) wrapper. It is meant to be used as a
    # configuration value. Subsequent `#call` calls always evaluate the given
    # block.
    #
    # @example
    #   num = 19
    #   value = Pry::Config::LazyValue.new { num += 1 }
    #   value.foo # => 20
    #   value.foo # => 21
    #   value.foo # => 22
    #
    # @api private
    # @since v0.13.0
    # @see Pry::Config::MemoizedValue
    class LazyValue
      def initialize(&block)
        @block = block
      end

      def call
        @block.call
      end
    end
  end
end