brew/Library/Homebrew/lazy_object.rb

21 lines
401 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2020-08-09 03:14:44 +02:00
# An object which lazily evaluates its inner block only once a method is called on it.
#
# @api private
2018-07-30 19:29:18 +02:00
class LazyObject < Delegator
def initialize(&callable)
super(callable)
end
def __getobj__
return @__delegate__ if defined?(@__delegate__)
2018-09-17 02:45:00 +02:00
2018-07-30 19:29:18 +02:00
@__delegate__ = @__callable__.call
end
def __setobj__(callable)
@__callable__ = callable
end
end