Explain the new Data class introduced in Ruby 3.2 and how it differs from Struct.
Last updated
Data(Ruby 3.2) defines immutable value objects viaData.define. It has no setters, andwithreturns a modified copy.Unlike
Struct, it is read-only and has no index access (s[0]). This signals value-object intent and prevents accidental mutation.Both auto-generate accessors,
==, andto_h, and accept a block for custom methods.Dataaccepts positional or keyword arguments innew.
- https://www.turing.com/interview-questions/ruby
- https://www.youtube.com/watch?v=lkunzd5uDrw
- https://blog.jacobvosmaer.nl/0004-ruby-scheduler-interaction/
- https://wohotech.in/coding/top-java-interview-questions
- https://jetthoughts.com/blog/ruby-3-4-yjit-performance-guide/
- https://speed.ruby-lang.org/
- https://flexiple.com/python/interview-questions