summaryrefslogtreecommitdiff
path: root/spec/ruby/optional
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-03-13 13:29:37 +0100
committerJean Boussier <[email protected]>2025-03-14 09:51:57 +0100
commitde48e47ddf78aba02fd9623bc7ce685540a10743 (patch)
treee4e7d409eb5d8343b85dc2628f5e1c8e7782b2dc /spec/ruby/optional
parentdd7deef338d843c8d866ddc279854068b39bfeb9 (diff)
Invoke `inherited` callbacks before `const_added`
[Misc #21143] Conceptually this makes sense and is more consistent with using the `Name = Class.new(Superclass)` alternative method. However the new class is still named before `inherited` is called.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12927
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r--spec/ruby/optional/capi/class_spec.rb11
-rw-r--r--spec/ruby/optional/capi/fixtures/class.rb10
2 files changed, 21 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/class_spec.rb b/spec/ruby/optional/capi/class_spec.rb
index a231245ebe..6d53b62b75 100644
--- a/spec/ruby/optional/capi/class_spec.rb
+++ b/spec/ruby/optional/capi/class_spec.rb
@@ -383,6 +383,17 @@ describe "C-API Class function" do
CApiClassSpecs.const_get(cls.name)
}.should raise_error(NameError, /wrong constant name/)
end
+
+ ruby_version_is "3.5" do
+ it "calls .inherited before .const_added" do
+ ScratchPad.record([])
+ @s.rb_define_class_id_under(CApiClassSpecs::Callbacks, :Subclass, CApiClassSpecs::Callbacks)
+ ScratchPad.recorded.should == [
+ [:inherited, "CApiClassSpecs::Callbacks::Subclass"],
+ [:const_added, :Subclass],
+ ]
+ end
+ end
end
describe "rb_define_class_id_under" do
diff --git a/spec/ruby/optional/capi/fixtures/class.rb b/spec/ruby/optional/capi/fixtures/class.rb
index b463e3b4c3..a738f2fd0f 100644
--- a/spec/ruby/optional/capi/fixtures/class.rb
+++ b/spec/ruby/optional/capi/fixtures/class.rb
@@ -101,4 +101,14 @@ class CApiClassSpecs
module M
end
end
+
+ class Callbacks
+ def self.inherited(child)
+ ScratchPad << [:inherited, child.name]
+ end
+
+ def self.const_added(const_name)
+ ScratchPad << [:const_added, const_name]
+ end
+ end
end