Feature #22404
openMake Data (and/or Struct, etc.) true "first-class citizens" and thank you!
Description
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
where the self:: is required to keep D_CONSTANT in the scope of D here.
Alternatively, we can write the following:
which reopens the D class to keep D_CONSTANT scoped to D or otherwise
which creates an anonymous class (which is not generally desired).
My proposal is for something like the following:
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
to
for Data, Struct, etc. and would address the last points mentioned in [1].
Updated by mame (Yusuke Endoh) about 6 hours ago
- Is duplicate of Feature #20993: Allow `class <constant-path> = <expression>` syntax added