Class: Rigor::Type::DataClass
- Inherits:
-
Object
- Object
- Rigor::Type::DataClass
- Includes:
- AcceptanceRouter, ValueSemantics
- Defined in:
- lib/rigor/type/data_class.rb
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 ⇒ Object
readonly
Returns the value of attribute class_name.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #bot ⇒ Object
- #describe(_verbosity = :short) ⇒ Object
- #dynamic ⇒ Object
- #erase_to_rbs ⇒ Object
-
#initialize(members, class_name = nil) ⇒ DataClass
constructor
A new instance of DataClass.
- #inspect ⇒ Object
- #top ⇒ Object
Methods included from ValueSemantics
Methods included from AcceptanceRouter
Constructor Details
#initialize(members, class_name = nil) ⇒ DataClass
Returns a new instance of DataClass.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rigor/type/data_class.rb', line 34 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 ⇒ Object (readonly)
Returns the value of attribute class_name.
29 30 31 |
# File 'lib/rigor/type/data_class.rb', line 29 def class_name @class_name end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
29 30 31 |
# File 'lib/rigor/type/data_class.rb', line 29 def members @members end |
Instance Method Details
#describe(_verbosity = :short) ⇒ Object
47 48 49 50 51 |
# File 'lib/rigor/type/data_class.rb', line 47 def describe(_verbosity = :short) return "singleton(#{class_name})" if class_name "Data.define(#{members.map(&:inspect).join(', ')})" end |
#dynamic ⇒ Object
65 66 67 |
# File 'lib/rigor/type/data_class.rb', line 65 def dynamic Trinary.no end |
#erase_to_rbs ⇒ Object
53 54 55 |
# File 'lib/rigor/type/data_class.rb', line 53 def erase_to_rbs "singleton(#{class_name || 'Data'})" end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/rigor/type/data_class.rb', line 75 def inspect "#<Rigor::Type::DataClass #{describe(:short)}>" end |