Clearly inspired by Python Data classes. Create immutable data structures.
Hash syntax does not work on them, use regular accessors. However there is a to_h to convert them to a hash for situations where that is useful.
You can initialise a Data class from a hash but you have to spread the values. Otherwise the string version of the hash becomes the first argument to the constructed object and if the class only has one field then an object is constructed.
Value equality seems to work as expected.
Data objects are immutable.
1
2Person = Data.define(:name, :age)
3
4joe = Person.new(name: "Joe", age: 32)
last updated: