-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Document order of execution const_added vs inherited #12759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
0a09fa1
to
6d23b38
Compare
Let me add. When However, I believe it is expected that the subclass has already a name in |
Oh, I have a use case! Since Zeitwerk nowadays sets autoloads for namespaces on |
Please file an issue on https://bugs.ruby-lang.org. |
Thanks @nobu, I have created ruby#21143. |
@@ -199,5 +199,25 @@ def self.const_added(name) | |||
|
|||
ScratchPad.recorded.should == [123, 456] | |||
end | |||
|
|||
it "for a class defined with the `class` keyword, const_added runs before inherited" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a class not using the class
keyword?
Then inherited
must run first since the inheritance happens before the assignment (if even assigned at all).
Could you add a spec for it too even though it's kind of obvious?
It also illustrates those 2 cases are inconsistent in the order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to test with module
too for extra coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a class not using the class keyword?
Yeah, I was like, that case is obvious because the hooks run in series, there is no ambiguity there. But happy to add a spec for completeness.
I'll update the patch later!
9c2accd
to
007d9bf
Compare
I don't have a real use where this matters, but thought perhaps you'd like to document the order of execution here.
If it was preferred to leave this unspecified, then I could redo the patch to say so.
What do you think?
/cc @byroot