Class: Rigor::Type::DataClass
- Inherits:
-
Object
- Object
- Rigor::Type::DataClass
- Includes:
- AcceptanceRouter, PlainLattice, ValueSemantics
- Defined in:
- lib/rigor/type/data_class.rb,
sig/rigor/type.rbs
Overview
The class object produced by Data.define(:x, :y) (ADR-48). Models the class, not an instance —
the value bound to Point in Point = Data.define(:x, :y) or the anonymous superclass in class Point < Data.define(:x, :y). Parameterised by the ordered member-name list so that Point.new(...)
can materialise a precise DataInstance.
class_name carries the binding name when known (the named-subclass form, ADR-48 slice 3) and is
nil for the anonymous result of a bare Data.define(...) before it is assigned to a constant. It
tags the instances .new produces; it does not change the carrier's folding behaviour.
Equality and hashing are structural over the member list and the class name. Two distinct
Data.define(:x) results are equal as types — they describe the same shape; the engine
distinguishes the constants they are bound to by the binding, not by the carrier.
See docs/adr/48-data-struct-value-folding.md.
Instance Attribute Summary collapse
-
#class_name ⇒ String?
readonly
Returns the value of attribute class_name.
-
#members ⇒ Array[Symbol]
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #== ⇒ Boolean
- #accepts ⇒ AcceptsResult
- #bot ⇒ Trinary
- #describe(_verbosity = :short) ⇒ String
- #dynamic ⇒ Trinary
- #erase_to_rbs ⇒ String
- #hash ⇒ Integer
-
#initialize(members, class_name = nil) ⇒ DataClass
constructor
A new instance of DataClass.
- #inspect ⇒ String
- #top ⇒ Trinary
Methods included from ValueSemantics
Constructor Details
#initialize(members, class_name = nil) ⇒ DataClass
Returns a new instance of DataClass.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rigor/type/data_class.rb', line 30 def initialize(members, class_name = nil) unless members.is_a?(Array) && members.all?(Symbol) raise ArgumentError, "members must be an Array of Symbols, got #{members.inspect}" end unless class_name.nil? || (class_name.is_a?(String) && !class_name.empty?) raise ArgumentError, "class_name must be a non-empty String or nil, got #{class_name.inspect}" end @members = members.dup.freeze @class_name = class_name&.freeze freeze end |
Instance Attribute Details
#class_name ⇒ String? (readonly)
Returns the value of attribute class_name.
25 26 27 |
# File 'lib/rigor/type/data_class.rb', line 25 def class_name @class_name end |
#members ⇒ Array[Symbol] (readonly)
Returns the value of attribute members.
25 26 27 |
# File 'lib/rigor/type/data_class.rb', line 25 def members @members end |
Instance Method Details
#== ⇒ Boolean
258 |
# File 'sig/rigor/type.rbs', line 258
def ==: (untyped other) -> bool
|
#accepts ⇒ AcceptsResult
257 |
# File 'sig/rigor/type.rbs', line 257
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
#describe(_verbosity = :short) ⇒ String
43 44 45 46 47 |
# File 'lib/rigor/type/data_class.rb', line 43 def describe(_verbosity = :short) return "singleton(#{class_name})" if class_name "Data.define(#{members.map(&:inspect).join(', ')})" end |
#erase_to_rbs ⇒ String
49 50 51 |
# File 'lib/rigor/type/data_class.rb', line 49 def erase_to_rbs "singleton(#{class_name || 'Data'})" end |
#hash ⇒ Integer
259 |
# File 'sig/rigor/type.rbs', line 259
def hash: () -> Integer
|
#inspect ⇒ String
61 62 63 |
# File 'lib/rigor/type/data_class.rb', line 61 def inspect "#<Rigor::Type::DataClass #{describe(:short)}>" end |