Class: LazyObject Private

Inherits:
Delegator show all
Defined in:
lazy_object.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

An object which lazily evaluates its inner block only once a method is called on it.

Instance Method Summary collapse

Constructor Details

#initialize(&callable) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • callable (Proc, nil)


9
10
11
12
13
14
15
16
17
# File 'lazy_object.rb', line 9

def initialize(&callable)
  # `Delegator` undefines `Kernel#raise` for instances.
  ::Kernel.raise ArgumentError, "LazyObject requires a block to evaluate lazily" if callable.nil?

  @__callable__ = T.let(callable, Proc)
  @getobj_set = T.let(false, T::Boolean)
  @__getobj__ = T.let(nil, T.untyped)
  super(callable)
end

Instance Method Details

#__getobj__(&_blk) ⇒ T.untyped

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • _blk (T.untyped)

Returns:

  • (T.untyped)


20
21
22
23
24
25
26
# File 'lazy_object.rb', line 20

def __getobj__(&_blk)
  return @__getobj__ if @getobj_set

  @__getobj__ = @__callable__.call
  @getobj_set = true
  @__getobj__
end

#__setobj__(callable) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • callable (Proc)


29
30
31
32
33
# File 'lazy_object.rb', line 29

def __setobj__(callable)
  @__callable__ = callable
  @getobj_set = false
  @__getobj__ = nil
end

#classT::Class[T.anything]

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (T::Class[T.anything])


47
# File 'lazy_object.rb', line 47

def class = __getobj__.class