Project

General

Profile

Actions

Feature #19555

open

Allow passing default options to `Data.define`

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

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:113033]

Description

Defining a subclass of Data with default attributes can currently be done by overriding intialize:

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:

Point = Data.define(:x, :y, z: 0)
Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0