Skip to content

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