Creating Classes on the Fly

If you need to create a Ruby class during run time you can use If you provide it with a class as an argument the given class becomes the superclass of the created class.

The Carrierwave gem uses this to create uploaders for file versions. Here is a simplified extract:

class Uploader
  def build_version(name, options)
    uploader =
    # ...

In the above, uploader will be a class whose parent class is Uploader.