2018-11-17 19:31:33 -05:00
|
|
|
class Pry
|
|
|
|
class Config < Pry::BasicObject
|
2018-11-20 08:10:21 -05:00
|
|
|
# The primary purpose for instances of this class is to be used as a
|
|
|
|
# configuration value that is computed upon each access, see {Pry.lazy}
|
2018-12-01 02:51:52 -05:00
|
|
|
# for more examples.
|
2018-11-17 19:31:33 -05:00
|
|
|
#
|
|
|
|
# @example
|
2018-12-01 02:51:52 -05:00
|
|
|
# num = 19
|
|
|
|
# _pry_.config.foo = Pry::Config::Lazy.new(&proc { num += 1 })
|
|
|
|
# _pry_.config.foo # => 20
|
|
|
|
# _pry_.config.foo # => 21
|
|
|
|
# _pry_.config.foo # => 22
|
2018-11-17 19:31:33 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
# @since v0.12.0
|
|
|
|
class Lazy
|
|
|
|
def initialize(&block)
|
|
|
|
@block = block
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [Object]
|
|
|
|
def call
|
|
|
|
@block.call
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-17 19:33:52 -05:00
|
|
|
end
|