Module#parent_name broken for frozen classes #27713
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
ref #27637 |
Can you squash down to one commit? Otherwise looks good to me. Thanks for working on this! |
Done! |
else | ||
@parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil | ||
end | ||
return @parent_name if defined?(@parent_name) |
rafaelfranca
Jan 18, 2017
Member
Can we keep the if/else
where. We prefer it over short-circuit returns.
Can we keep the if/else
where. We prefer it over short-circuit returns.
@rafaelfranca Updated to reflect your concerns. Cheers! |
Module#parent_name broken for frozen classes
Backported 9f4fc67 |
Previously memoization inside of
Module.parent_name
resulted in a runtime error when called for the first time on a frozen module. This patch adds a regression test and refactors the method to resolve the issue.Note: introspection tests were previously lumped into
test/core_ext/module_test.rb
despite the code having been extracted tocore_exts/module/introspection.rb
. I isolated the tests similarly, following convention (e.g.,core_exts/module/anonymous.rb
totest/core_ext/module/anonymous_test.rb
). In the process, I removed some old (over 10 years) setup objects that were no longer being referenced.