Blog (ruby)

https://www.gravatar.com/avatar/2735068c913a072744a799e3c0833b7b?d=mp&s=80 @fredwu 16 years ago | 1 min read | no comments
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.