Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid error when member is present on ancestor class #1068

Merged
merged 2 commits into from
Oct 19, 2024

Conversation

francesmcmullin
Copy link
Contributor

Fix #1067

Niche case - when clearing class members for new definition, avoid trying to remove members present on ancestor classes.

I'm happy to make any updates for style or structure if needed - I've added a spec that does fail without this fix, very happy to receive feedback if it would fit better in a different location or with different emphasis.

Niche case - when clearing class members for new definition,
avoid trying to remove members present on ancestor classes.
@@ -26,6 +26,18 @@
expect(clazz.ancestors).to include described_class
end

it 'ignores methods on ancestor classes' do
ancestor = described_class.ancestors.first
Copy link
Collaborator

Choose a reason for hiding this comment

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

described_class.ancestors.first is the same as described_class, no?
Unless prepended modules are involved here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I double checked and it works as well using ancestors.last 👍🏻

Comment on lines 33 to 36
clazz = described_class.new(:foo)
expect{ described_class.const_get(clazz.to_s) }.to raise_error(NameError)
expect(clazz).to be_a Class
expect(clazz.ancestors).to include described_class
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems not meaningful to test here, let's just that that creating an instance of it plus accessing that member works as expected.

@francesmcmullin
Copy link
Contributor Author

I've updated the spec now based on comments - the ancestor method is added to the end of the ancestor chain, and I'm testing the more relevant method presence and arity.

Copy link
Collaborator

@eregon eregon left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@eregon eregon merged commit 56227a4 into ruby-concurrency:master Oct 19, 2024
14 checks passed
@francesmcmullin francesmcmullin deleted the fix-padrino-compat branch October 19, 2024 18:36
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.

Incompatibility with Padrino framework
2 participants