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

String#constantize vs simple comparison #200

Merged
merged 4 commits into from
Jun 24, 2022

Conversation

wasaylor
Copy link
Contributor

@wasaylor wasaylor commented Jun 6, 2022

If you're writing a Rails app, you may reach for String#constantize (provided by Active Support Core Extensions) when you have a variable that may resolve to a class name and your control flow is to execute that classes code in some manner.

This benchmarks using String#constantize vs a simple comparison, showing the latter is much faster.

@wasaylor wasaylor marked this pull request as ready for review June 6, 2022 20:48
@wasaylor wasaylor changed the title String#constantize vs simple comparison for inflections String#constantize vs simple comparison Jun 6, 2022
Copy link
Contributor

@lubc lubc left a comment

Choose a reason for hiding this comment

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

@wasaylor Thanks for your contribution!

@lubc lubc merged commit e860f60 into fastruby:master Jun 24, 2022
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