Mark Chavez
eat. sleep. repeat. 👾 coding, ⌨️ keyboarding, 🚴🏼 cycling.
Creating ruby constants from strings safely 08/02/2023
Using the .constantize method
# If the constant does not exist, this will raise a NoMethodError exception
"Foo::Bar".constantize
Safer alternative: Using the .safe_constantize method
# It returns nil if the constant does not exist
"Foo::Bar".safe_constantize