3 ms·
They’re both shortcuts to creating class-like things. Take @dataclass in python for example, that’s similar to Struct for Ruby. ‘Data’ documentation from the
by bfung 4y ago
They’re both shortcuts to creating class-like things.
Take @dataclass in python for example, that’s similar to Struct for Ruby.
‘Data’ documentation from the GitHub PR (https://zverok.space/ruby-rdoc/Data.html https://zverok.space/ruby-rdoc/Data.html):
Data provides no member writers, or enumerators: it is meant to be a storage for immutable atomic values. But note that if some of data members is of a mutable class, Data does no additional immutability enforcement
See also Struct, which is a similar concept, but has more container-alike API, allowing to change contents of the object and enumerate it.
- masklinn 4y ago> Take @dataclass in python for example, that’s similar to Struct for Ruby. From a cursory look data classes seem to do a lot more than structs. Structs seem like a mutable version of namedtuples, or js objects, down to behaving like a collection / iterable.