Skip to content

Class reloading#56

Merged
dblock merged 5 commits into
dblock:masterfrom
flvrone:class-reloading
Jun 20, 2026
Merged

Class reloading#56
dblock merged 5 commits into
dblock:masterfrom
flvrone:class-reloading

Conversation

@flvrone

@flvrone flvrone commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Sometimes when accessing enum classes from rails console - DuplicateKeyError is raised, because the class was already loaded (evaluated), but then for whatever reason it tried to load again (evaluate the whole body again), and the previous definitions are still in those instance variables, so it breaks.

Now upon including the module - the instance variable is cleared, and it does not break inheritance. (This issue #49 was already solved and tested, and my PR does not break it).

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@dblock dblock left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! Update CHANGELOG and take care of my nits below?

Comment thread spec/ruby-enum/enum_spec.rb Outdated
Comment thread spec/ruby-enum/enum_spec.rb Outdated
@flvrone

flvrone commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Hey @dblock, thanks for review!
I have added another test, interesting one, related to inheritance.

I believe that the documentation should be updated regarding inheritance.
As this is right now - IMO the only reliable way for it to work without errors -
is to always explicitly include Ruby::Enum in every subclass.

I think that if we want it to avoid it - that would require a different implementation and notation, probably something similar to this:
https://hanakai.org/learn/dry/dry-validation/v1.11/schemas#re-using-schemas

Notice how schemas are not explicitly defined as classes, but rather are results of some function with the given block.
And then multiple schemas are not inherited, but composed.

Also, would you please release the new version of this gem with my fix?
I would like to update it in my project. 😅

@flvrone flvrone requested a review from dblock June 17, 2026 12:04
@dblock dblock merged commit cd5cea4 into dblock:master Jun 20, 2026
10 checks passed
@dblock

dblock commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Merged, thank you. Please feel free to PR doc updates or a completely different implementation that solves the include problem if you think it's better and can make it work!

@dblock

dblock commented Jun 20, 2026

Copy link
Copy Markdown
Owner

I released 1.1.0.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants