Project

General

Profile

Feature #19555

Updated by p8 (Petrik de Heus) over 1 year ago

Defining a subclass of `Data` with default attributes can currently be done implemented 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) 
 ```

Back