Tips for Job Interviews as a Junior Software Developer Sep 27, 2020
As coding bootcamps such as Coder Academy and General Assembly churn out more and more software developers, and as more and more people…
So we want to dynamically instantiate an object (i.e. convert a string to a class constant).
Instead of doing this:
@dynamic_var = "User"
eval(@dynamic_var)
You can do this:
@dynamic_var = "User"
@dynamic_var.constantize
See more about the constantize
method in Rails’s API.