Hulihan Applications
about projects portfolio services contact_us
Converting a String to a Class in Ruby

    

In Ruby, you can easily convert a string, or any kind of text, into a Class. Here's a quick example:

class_name = "new_class" # set string with name of class, will camelize to NewClass 
new_object = class_name.camelize.constantize.new # call NewClass.new

Tags:

0 Comments


Add A Comment



simple_captcha.jpg



Hulihan Applications © 2007-2009
No portion of this site may be copied, altered, duplicated or otherwise used without the express written approval of Hulihan Applications.