Class: Rigor::Type::Nominal

Inherits:
Object
  • Object
show all
Includes:
AcceptanceRouter, PlainLattice, ValueSemantics
Defined in:
lib/rigor/type/nominal.rb,
sig/rigor/type.rbs

Overview

An instance type for a Ruby class or module. The class is identified by its fully-qualified Ruby name; the registry attached to the environment owns the class lookup.

Slice 4 phase 2d adds type_args: an ordered, frozen array of Rigor::Type values that carry the receiver's generic instantiation. The empty array is the canonical "raw" form (Nominal[Array]); a non-empty array represents an applied generic (Nominal[Array, [Integer]]). Two Nominals are structurally equal only when their class_name AND type_args match, so the raw form and any applied form are intentionally distinct values. Acceptance routes treat the raw form leniently for backward compatibility with phase 2b call sites that have not yet learned to carry generics.

Type arguments MUST be Rigor::Type instances. The constructor freezes the array; callers MUST NOT mutate it after construction.

See docs/type-specification/rbs-compatible-types.md.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ValueSemantics

included

Constructor Details

#initialize(class_name, type_args = []) ⇒ Nominal

Returns a new instance of Nominal.

Parameters:

  • class_name (String)
  • type_args (Array[Type::t]) (defaults to: [])

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
# File 'lib/rigor/type/nominal.rb', line 27

def initialize(class_name, type_args = [])
  raise ArgumentError, "class_name must be a String, got #{class_name.class}" unless class_name.is_a?(String)
  raise ArgumentError, "class_name must not be empty" if class_name.empty?
  raise ArgumentError, "type_args must be an Array, got #{type_args.class}" unless type_args.is_a?(Array)

  @class_name = class_name.freeze
  @type_args = type_args.dup.freeze
  freeze
end

Instance Attribute Details

#class_nameString (readonly)

Returns the value of attribute class_name.

Returns:

  • (String)


25
26
27
# File 'lib/rigor/type/nominal.rb', line 25

def class_name
  @class_name
end

#type_argsArray[Type::t] (readonly)

Returns the value of attribute type_args.

Returns:

  • (Array[Type::t])


25
26
27
# File 'lib/rigor/type/nominal.rb', line 25

def type_args
  @type_args
end

Instance Method Details

#==Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


118
# File 'sig/rigor/type.rbs', line 118

def ==: (untyped other) -> bool

#acceptsAcceptsResult

Parameters:

  • other (Type::t)
  • mode: (accepts_mode)

Returns:



117
# File 'sig/rigor/type.rbs', line 117

def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult

#botTrinary

Returns:



115
# File 'sig/rigor/type.rbs', line 115

def bot: () -> Trinary

#describe(verbosity = :short) ⇒ String

Parameters:

  • verbosity (Symbol) (defaults to: :short)

Returns:

  • (String)


37
38
39
40
41
42
# File 'lib/rigor/type/nominal.rb', line 37

def describe(verbosity = :short)
  return class_name if type_args.empty?

  rendered = type_args.map { |t| t.describe(verbosity) }.join(", ")
  "#{class_name}[#{rendered}]"
end

#dynamicTrinary

Returns:



116
# File 'sig/rigor/type.rbs', line 116

def dynamic: () -> Trinary

#erase_to_rbsString

Returns:

  • (String)


44
45
46
47
48
49
# File 'lib/rigor/type/nominal.rb', line 44

def erase_to_rbs
  return class_name if type_args.empty?

  rendered = type_args.map(&:erase_to_rbs).join(", ")
  "#{class_name}[#{rendered}]"
end

#hashInteger

Returns:

  • (Integer)


119
# File 'sig/rigor/type.rbs', line 119

def hash: () -> Integer

#inspectString

Returns:

  • (String)


59
60
61
# File 'lib/rigor/type/nominal.rb', line 59

def inspect
  "#<Rigor::Type::Nominal #{describe(:short)}>"
end

#topTrinary

Returns:



114
# File 'sig/rigor/type.rbs', line 114

def top: () -> Trinary