Explain the new Data class introduced in Ruby 3.2 and how it differs from Struct.

Last updated 27 June 2026

  • Data (Ruby 3.2) defines immutable value objects via Data.define. It has no setters, and with returns 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, ==, and to_h, and accept a block for custom methods. Data accepts positional or keyword arguments in new.

  • 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
All Ruby interview questions