Quick ref – Kernel.const_get and .constantize

July 26th, 2011 by andy Leave a reply »

Just a quick ref. If you have a string that matches a class name in your app, you can use that string to interact with that model. Here’s how:

string = “User”

string.constantize OR Kernel.const_get(string) – the former only works in rails (as it’s part of ActiveSupport::Inflector)

Advertisement

Leave a Reply