Tips for Writing a Good CV / Résumé May 20, 2020
Due to COVID-19, not many companies are hiring at the moment. The company I work for therefore is in a very fortunate position to still be…
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.