Using a Rails initializer to create classes dynamically in Ruby

At the moment I’m working on a project where I want to dynamically create a set of classes in a RoR application.  This handy little snippet will create a class that extends a super class.

Object.const_set(‘YOUR_CLASS_NAME_HERE’, Class.new(RestfulController))

Thats pretty easy.

If you want it to happen automatically when you start your Rails app, create a .rb file in /config/initializers   …. Any code found in there will be run when the app starts up.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s