
Issue #19555 has been updated by zverok (Victor Shepelev). This is not simple as it seems (that's why we abstained of introducing something like that). Imagine this: ```ruby Point = Data.define(:x, :y, tags: []) p1 = Point.new(1, 2) p1.tags << 'foo' p2 = Point2.new(3, 4) p2.tags #=>? ``` In naive implementation, `p1.tags` is the same ary as passed for default, and `p1.tags << 'foo'` adjusts the default value. In less naive implementation, we need probably `.dup` defaults, which still might be not enough or impossible. Yes, mutable values are kinda against Data idea, but it doesn’t mean nobody will do that. ---------------------------------------- Feature #19555: Allow passing default options to `Data.define` https://bugs.ruby-lang.org/issues/19555#change-102574 * Author: p8 (Petrik de Heus) * Status: Open * Priority: Normal ---------------------------------------- Defining a subclass of `Data` with default attributes can currently be done by overriding `intialize`: ```ruby class Point < Data.define(:x, :y, :z) def initialize(x:, y:, z: 0) = super end p Point.new(1, 2) #=> #<data Point x=1, y=2, z=0> ``` It would be nice if we could do it in `define` as well: ```ruby Point = Data.define(:x, :y, z: 0) ``` -- https://bugs.ruby-lang.org/