Project

General

Profile

Actions

Bug #21375

open

Set[] does not call #initialize

Added by Ethan (Ethan -) 2 days ago. Updated 1 day ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-05-26T17:42:35Z master 909a0daab6) +PRISM [x86_64-darwin22]
[ruby-core:122303]

Description

I have a subclass of Set that overrides #initialize. Following #21216, .new does call #initialize but .[] does not.

class MySet < Set
  def initialize(enum = nil)
    compare_by_identity
    super
  end
end

MySet.new.compare_by_identity?
# => true
MySet[].compare_by_identity?
# => false
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0