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
# File 'lazy_object.rb', line 9

def initialize(&callable)
  @__callable__ = T.let(nil, T.nilable(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)


17
18
19
20
21
22
23
# File 'lazy_object.rb', line 17

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

  @__getobj__ = T.must(@__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, nil)


26
27
28
29
30
# File 'lazy_object.rb', line 26

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])


44
# File 'lazy_object.rb', line 44

def class = __getobj__.class