diff options
author | Xavier Noria <[email protected]> | 2025-02-16 20:30:40 +0100 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-04-10 10:33:36 +0200 |
commit | 08ce6268ee1690f003af40b9357272d43e990d75 (patch) | |
tree | 0d04ac6c12879fa0d80e4a387561f1bd51541a1d /spec/ruby/core | |
parent | b47a04eb9151a9fa59979fbaf20deeb404822959 (diff) |
Document order of execution const_added vs inherited
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12759
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/module/const_added_spec.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/ruby/core/module/const_added_spec.rb b/spec/ruby/core/module/const_added_spec.rb index 4b10dd5963..1b3dad514b 100644 --- a/spec/ruby/core/module/const_added_spec.rb +++ b/spec/ruby/core/module/const_added_spec.rb @@ -199,5 +199,25 @@ describe "Module#const_added" do ScratchPad.recorded.should == [123, 456] end + + it "for a class defined with the `class` keyword, const_added runs before inherited" do + ScratchPad.record [] + + mod = Module.new do + def self.const_added(_) + ScratchPad << :const_added + end + end + + parent = Class.new do + def self.inherited(_) + ScratchPad << :inherited + end + end + + class mod::C < parent; end + + ScratchPad.recorded.should == [:const_added, :inherited] + end end end |