From: Martin Boese Date: 2008-04-02T20:02:44+09:00 Subject: Re: Dynamic class names No... I mean the 'Name' of a class or module (that what you get with object.class.name). The doc of Class::new (ri) describes how it works: > You can give a class a name by assigning the class object to a constant. ...but still that doesn't allow me to set the initial name when _defining_ the class. I am aware that this can be done using eval with the complete class definition as a string - which is also not what I want. The reason is to avoid name clashes of a larger program. So I am thinking of using some central instance to assign names and address specific types of classes. Martin On Wednesday 02 April 2008 10:58:52 Phillip Gawlowski wrote: > Martin Boese 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" > > Yes. Here is an overview on metaprogramming, and two ways to create > classes dynamically: > > http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html > > -- Phillip Gawlowski