Martin Boese
4/2/2008 12:16:00 PM
Thanks, that's what I was looking for.
That example of mine now works:
name = 'Test'
Object::const_set(name.intern, Class::new do
def write
puts "TEST"
end
end
)
Object::const_get(name).new.write # writes => "TEST"
martin
On Wednesday 02 April 2008 12:19:33 Robert Dober wrote:
> On Wed, Apr 2, 2008 at 11:18 AM, Martin Boese <boesemar@gmx.de> wrote:
> > Is it possible to create classes with a dynamic name? Example:
> >
> > name = "Test"
> >
> > class name # this fails
> > def write
> > puts "TEST"
> > end
> > end
> >
> > puts Object::const_get(name).new.write # => "TEST"
>
> sure
>
> c = Class::new {
> def a; 41 end
> }
> d = Class::new(c) {
> def a; super.succ end
> }
> d.new.a --> 42
>
> HTH
> Robert