From 5f3fb35a14665374f353d3889ded3e8a0061895a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 20 Apr 2025 23:43:02 +0200 Subject: [PATCH] Add a new spec for inherited --- spec/ruby/core/class/inherited_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/ruby/core/class/inherited_spec.rb b/spec/ruby/core/class/inherited_spec.rb index 8ef8bb8c35..2a8d1ff813 100644 --- a/spec/ruby/core/class/inherited_spec.rb +++ b/spec/ruby/core/class/inherited_spec.rb @@ -98,4 +98,21 @@ describe "Class.inherited" do -> { Class.new(top) }.should_not raise_error end + it "if the subclass is assigned to a constant, it is all set" do + ScratchPad.record [] + + parent = Class.new do + def self.inherited(subclass) + ScratchPad << defined?(self::C) + ScratchPad << const_defined?(:C) + ScratchPad << constants + ScratchPad << const_get(:C) + ScratchPad << subclass.name.match?(/\A#::C\z/) + end + end + + class parent::C < parent; end + + ScratchPad.recorded.should == ["constant", true, [:C], parent::C, true] + end end