Module: Stoplight::Types

Defined in:
lib/stoplight/types.rb

Class Method Summary collapse

Class Method Details

.must(value) ⇒ T

Asserts a value is non-nil, returning it with a narrowed type.

Use this to satisfy Steep’s flow typing when you know a nilable value must be present. Prefer this over type assertions (#: Type) since it provides runtime validation.

Examples:

Validating required configuration

@window_size = T.must(config.window_size)

Returns:

  • (T)

    the non-nil value

Raises:

  • (TypeError)

    if value is nil



21
22
23
24
25
26
27
# File 'lib/stoplight/types.rb', line 21

def self.must(value)
  if value.nil?
    raise TypeError, "must not have nil value"
  else
    value
  end
end

.undefinedObject



7
# File 'lib/stoplight/types.rb', line 7

def self.undefined = Undefined.instance