Skip to content

String#constantize vs simple comparison - #200

Merged
lubc merged 4 commits into
fastruby:masterfrom
wasaylor:constantize-vs-comparison
Jun 24, 2022
Merged

String#constantize vs simple comparison#200
lubc merged 4 commits into
fastruby:masterfrom
wasaylor:constantize-vs-comparison

Conversation

@wasaylor

@wasaylor wasaylor commented Jun 6, 2022

Copy link
Copy Markdown
Contributor

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 Jun 6, 2022

@lubc lubc left a comment

Copy link
Copy Markdown
Contributor

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

2 participants