From: "asoffa (Aaron Soffa) via ruby-core" Date: 2026-10-04T22:30:23+00:00 Subject: [ruby-core:126919] [Ruby Feature#22404] Make Data (and/or Struct, etc.) true "first-class citizens" and thank you! Issue #22404 has been reported by asoffa (Aaron Soffa). ---------------------------------------- Feature #22404: Make Data (and/or Struct, etc.) true "first-class citizens" and thank you! https://bugs.ruby-lang.org/issues/22404 * Author: asoffa (Aaron Soffa) * Status: Open ---------------------------------------- First of all, I would like to give a **huge** shoutout to the Ruby community for staying true to Ruby's mission of increasing developer productivity and thereby happiness and thereby enrichment of people's lives, especially mine in so many ways! THANK YOU! As a scientist (who likes data), I have ultimately so far discovered **only** this (relatively minor!) nitpick about the Ruby programming language: data/value objects are not "first-class citizens" for constants in the way that general modules and classes are. The current solution is to write something like ```ruby D = Data.define(:x, :y) do self::D_CONSTANT = 1 end ``` where the `self::` is required to keep `D_CONSTANT` in the scope of `D` here. Alternatively, we can write the following: ```ruby D = Data.define(:x, :y) class D D_CONSTANT = 1 end ``` which reopens the `D` class to keep `D_CONSTANT` scoped to `D` or otherwise ```ruby class D < Data.define(:x, :y) D_CONSTANT = 1 end ``` which creates an anonymous class (which is not generally desired). My proposal is for something like the following: ```ruby class D = Data.define(:x, :y) D_CONSTANT = 1 end ``` to avoid the above complications. This enhancement request may or may not make sense depending on how frequently `Data` (and/or `Struct`, etc.) are to be considered "first-class citizens" in Ruby. My thought is that the `=` in the class definition here very nicely dovetails with the `<` for creating subclasses and also with the relatively new `=` syntax now allowed for method definitions (e.g. `def f = 1`). This enhancement would be analogous to allowing upgrading ```ruby C = Class.new do self::C_CONSTANT = 1 end ``` to ```ruby class C C_CONSTANT = 1 end ``` for `Data`, `Struct`, etc. and would address the last points mentioned in [1]. [1] https://bugs.ruby-lang.org/issues/16122 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/