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.
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.