Inherit keys, key?, value?, key, value, to_h, parse and each from superclass - #59
Merged
Conversation
Danger ReportNo issues found. |
…erclass Follow-up to #49/#58. values already merged enums from a superclass chain, but keys, key?, value?, key, value, to_h, parse and each only looked at a class' own enums, silently ignoring any enums defined in a superclass. Introduces _enum_hash/_enums_by_value that merge a class' own enums with those of its superclass chain (subclass definitions take precedence over the same key/value defined in a superclass), and uses them for all read methods. define/duplicate validation continues to use the class' own enums only (_own_enum_hash/_own_enums_by_value), so a subclass may still redefine a key or value already used by a superclass. Documents the change in README.md and UPGRADING.md, and adds tests covering a subclass redefining a parent class' key. Co-authored-by: Copilot <[email protected]>
dblock
force-pushed
the
subclass-inherited-values
branch
from
August 15, 2026 01:26
2ce77b1 to
e11b310
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #49 / #58.
valuesalready merges enums from a class' entire superclass chain, butkeys,key?,value?,key,value,to_h,parseandeachonly looked at a class' own enums, silently ignoring anything defined in a superclass:Fix
Introduces
_enum_hash/_enums_by_valueprivate methods that merge a class' own enums with those of its superclass chain (a subclass' own definitions take precedence over an identically-named key/value defined in a superclass). All read methods (keys,key?,value?,key,value,to_h,parse,each,each_key,each_value) now use these merged views, consistent withvalues.define's duplicate-key/duplicate-value validation still only looks at the class' own enums (via new_own_enum_hash/_own_enums_by_value), preserving the existing (and tested) ability for a subclass to redefine a key or value already used by a superclass.Testing
FirstSubclass(which defines its own enums) andSubclassWithNoOwnDefines(from Fix NoMethodError on enum methods when subclass defines no enums of its own #58) coveringkeys,key?,value?,key,value,to_h,parse, andeach.bundle exec rspec spec/- 63 examples, 0 failures, 100% line coverage.bundle exec rubocop- clean.spec_i18nsuite - 3 examples, 0 failures.