On Feb 6, 2008 8:32 PM, macaco <macacoangel@gmail.com> wrote:
> I've found this:
>
> def create_class(var)
> #instantiate class type[var]
> foo = Object.const_get(type[var])
> sub = foo.new
> puts "#{sub.class}"
> end
>
> Works for me!
So you're not creating a class, really. You're creating an instance of
already-defined classes. Right?
You can smash those down to one line and get rid of your holder
variable, if you like:
def create_thing var
sub = Object.const_get(type[var]).new
puts sub.class
end
I'm not a huge fan of holder variables, myself, but your mileage may
vary, of course.
Ben