You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for sub/superclasses (NoMethodError: undefined method `values' for nil ?) #49
I have an older project, just updated to rails 6.1 and ruby 3. However, I am seeing an issue when trying to read the values from here, and not sure why
Ah, think I figured it out. I had include Ruby::Enum in the superclass PostMediaType, even though I put it here to try and simplify it. The @_enum_hash seems to have not been accessible that way. Moving include Ruby::Enum into every subclass directly, and removing from the super class works again.
changed the title [-]NoMethodError: undefined method `values' for nil ?[/-][+]Add support for sub/superclasses (NoMethodError: undefined method `values' for nil ?)[/+]on Aug 14, 2024
Activity
coneybeare commentedon Aug 14, 2024
Ah, think I figured it out. I had
include Ruby::Enumin the superclassPostMediaType, even though I put it here to try and simplify it. The@_enum_hashseems to have not been accessible that way. Movinginclude Ruby::Enuminto every subclass directly, and removing from the super class works again.dblock commentedon Aug 14, 2024
I think supporting superclass enums is a very desirable feature! Let's reopen this.
Want to try and write some (failing) specs and maybe an implementation?
[-]NoMethodError: undefined method `values' for nil ?[/-][+]Add support for sub/superclasses (NoMethodError: undefined method `values' for nil ?)[/+]pldavid2 commentedon Feb 17, 2026
Related to this issue, changing
ruby-enum/lib/ruby-enum/enum.rb
Line 126 in 7b3e255
result = (@_enum_hash || {}).values.map(&:value)make it possible to have a subclass without defining new constants.
dblock commentedon Feb 20, 2026
@pldavid2 attempt a PR?
dblock commentedon Aug 15, 2026
Copilot fixed it for us in #58
Fix NoMethodError when a subclass defines no enums of its own
Inherit keys, key?, value?, key, value, to_h, parse and each from sup…