Module#parent_name broken for frozen classes #27713

merged 1 commit into from Jan 18, 2017


None yet

5 participants


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 to core_exts/module/introspection.rb. I isolated the tests similarly, following convention (e.g., core_exts/module/anonymous.rb to test/core_ext/module/anonymous_test.rb). In the process, I removed some old (over 10 years) setup objects that were no longer being referenced.


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!



- 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.

@coreyward coreyward Adjust `Module.parent_name` to work when frozen; fixes #27637

@rafaelfranca Updated to reflect your concerns.


@rafaelfranca rafaelfranca merged commit 5ac8af2 into rails:master Jan 18, 2017

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
codeclimate no new or fixed issues
@coreyward coreyward deleted the coreyward:module_freeze_parent_name branch Jan 18, 2017

Backported 9f4fc67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment