Project

General

Profile

Actions

Bug #19259

closed

`Data#with` doesn't call `initialize` nor `initialize_copy`

Added by ko1 (Koichi Sasada) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:111431]

Description

Data#with doesn't call initialize nor initialize_copy.
It is confirmation request.

class P < Data.define(:x, :y)
  def initialize_copy(...)
    p :initialize_copy
    super
  end

  def initialize(...)
    p :initialize
    super
  end
end

pt = P.new(1, 2)
#=> :initialize
pt.clone
#=> :initialize_copy
pt.dup
#=> :initialize_copy
pt.with(x: 10)
#=> N/A

For example, if an author of P add validation code, #with skips it.


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #19000: Data: Add "Copy with changes method" [Follow-on to #16122 Data: simple immutable value object]ClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like1Like0Like0Like0Like0