Class: Rigor::Type::Tuple
- Inherits:
-
Object
- Object
- Rigor::Type::Tuple
- Includes:
- AcceptanceRouter, PlainLattice, ValueSemantics
- Defined in:
- lib/rigor/type/tuple.rb,
sig/rigor/type.rbs
Overview
A heterogeneous, fixed-arity array shape. Inhabitants are exactly the Ruby Array instances whose
length matches elements.size and whose element at position i inhabits elements[i].
In RBS this corresponds to the tuple form [A, B, C]. A tuple is always a subtype of
Array[union(elements)]; method dispatch therefore degrades to the underlying Nominal[Array, [union]] while acceptance keeps the per-position precision.
Slice 5 phase 1 introduces the carrier and surfaces it from the ArrayNode literal handler when
every element is a non-splat value. Tuple-aware refinements (tuple[0], tuple.first,
destructuring) are implemented in ShapeDispatch, which runs above
Inference::MethodDispatcher::RbsDispatch.
Equality and hashing are structural across an ordered, frozen element list. The empty Tuple
Tuple[] is permitted; the array literal handler keeps [] as raw Nominal[Array] (no element
evidence to lock the arity), but external constructors MAY build Tuple[] directly when the
zero-arity discipline is intended.
See docs/type-specification/rbs-compatible-types.md (tuple) and docs/type-specification/rigor-extensions.md (hash-shape and tuple kin).
Instance Attribute Summary collapse
-
#elements ⇒ Array[Type::t]
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #== ⇒ Boolean
- #accepts ⇒ AcceptsResult
- #bot ⇒ Trinary
- #describe(verbosity = :short) ⇒ String
- #dynamic ⇒ Trinary
- #erase_to_rbs ⇒ String
- #hash ⇒ Integer
-
#initialize(elements) ⇒ Tuple
constructor
A new instance of Tuple.
- #inspect ⇒ String
- #top ⇒ Trinary
Methods included from ValueSemantics
Constructor Details
#initialize(elements) ⇒ Tuple
Returns a new instance of Tuple.
32 33 34 35 36 37 |
# File 'lib/rigor/type/tuple.rb', line 32 def initialize(elements) raise ArgumentError, "elements must be an Array, got #{elements.class}" unless elements.is_a?(Array) @elements = elements.dup.freeze freeze end |
Instance Attribute Details
#elements ⇒ Array[Type::t] (readonly)
Returns the value of attribute elements.
30 31 32 |
# File 'lib/rigor/type/tuple.rb', line 30 def elements @elements end |
Instance Method Details
#== ⇒ Boolean
220 |
# File 'sig/rigor/type.rbs', line 220
def ==: (untyped other) -> bool
|
#accepts ⇒ AcceptsResult
219 |
# File 'sig/rigor/type.rbs', line 219
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
#describe(verbosity = :short) ⇒ String
39 40 41 42 43 |
# File 'lib/rigor/type/tuple.rb', line 39 def describe(verbosity = :short) return "[]" if elements.empty? "[#{elements.map { |t| t.describe(verbosity) }.join(', ')}]" end |
#erase_to_rbs ⇒ String
45 46 47 48 49 |
# File 'lib/rigor/type/tuple.rb', line 45 def erase_to_rbs return "[]" if elements.empty? "[#{elements.map(&:erase_to_rbs).join(', ')}]" end |
#hash ⇒ Integer
221 |
# File 'sig/rigor/type.rbs', line 221
def hash: () -> Integer
|
#inspect ⇒ String
59 60 61 |
# File 'lib/rigor/type/tuple.rb', line 59 def inspect "#<Rigor::Type::Tuple #{describe(:short)}>" end |