Skip to content

Class reloading#56

Open
flvrone wants to merge 2 commits into
dblock:masterfrom
flvrone:class-reloading
Open

Class reloading#56
flvrone wants to merge 2 commits into
dblock:masterfrom
flvrone:class-reloading

Conversation

@flvrone

@flvrone flvrone commented Jun 16, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Danger Report

Warnings

  • Unless you're refactoring existing code or improving documentation, please update CHANGELOG.md.

Markdowns

Here's an example of a CHANGELOG.md entry:

* [#56](https://github.com/dblock/ruby-enum/pull/56): Class reloading - [@flvrone](https://github.com/flvrone).

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?

end
end

# rubocop:disable Rspec/DescribedClass

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.

Let's just rubocop -a; rubocop --auto-gen-config these or disable the rule?


# rubocop:disable Rspec/DescribedClass
describe 'Reloading enum definition' do
it 'plays nice with lazy loading in Ruby on Rails' do

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.

Nit: maybe just say "can be lazy reloaded" ... also bald is not a hairstyle :)

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