Class: Rigor::Type::Tuple
- Inherits:
-
Object
- Object
- Rigor::Type::Tuple
- Includes:
- AcceptanceRouter, ValueSemantics
- Defined in:
- lib/rigor/type/tuple.rb
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`.
In RBS this corresponds to the tuple form ‘[A, B, C]`. A tuple is always a subtype of `Array`; 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 for `tuple`, `tuple.first`, and destructuring assignment are deferred to Slice 5 phase 2; they will run as a higher-priority dispatch tier 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` (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 ⇒ Object
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #bot ⇒ Object
- #describe(verbosity = :short) ⇒ Object
- #dynamic ⇒ Object
- #erase_to_rbs ⇒ Object
-
#initialize(elements) ⇒ Tuple
constructor
A new instance of Tuple.
- #inspect ⇒ Object
- #top ⇒ Object
Methods included from ValueSemantics
Methods included from AcceptanceRouter
Constructor Details
#initialize(elements) ⇒ Tuple
Returns a new instance of Tuple.
37 38 39 40 41 42 |
# File 'lib/rigor/type/tuple.rb', line 37 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 ⇒ Object (readonly)
Returns the value of attribute elements.
35 36 37 |
# File 'lib/rigor/type/tuple.rb', line 35 def elements @elements end |
Instance Method Details
#describe(verbosity = :short) ⇒ Object
44 45 46 47 48 |
# File 'lib/rigor/type/tuple.rb', line 44 def describe(verbosity = :short) return "[]" if elements.empty? "[#{elements.map { |t| t.describe(verbosity) }.join(', ')}]" end |
#erase_to_rbs ⇒ Object
50 51 52 53 54 |
# File 'lib/rigor/type/tuple.rb', line 50 def erase_to_rbs return "[]" if elements.empty? "[#{elements.map(&:erase_to_rbs).join(', ')}]" end |
#inspect ⇒ Object
74 75 76 |
# File 'lib/rigor/type/tuple.rb', line 74 def inspect "#<Rigor::Type::Tuple #{describe(:short)}>" end |