Brian Candler <B.Candler / pobox.com> writes:

> On Thu, Feb 20, 2003 at 01:26:42AM +0900, Yukihiro Matsumoto wrote:
>> |I want a general method to add a member to the class dynamically, so if
>> |there were
>> |    Struct#add_member
>> |I would happily use it.
>    klassname="Foo"
>    eval "class #{klassname} ... "
>
> because this seems like a last resort :-)

I wouldn't be averse to using the string version of eval for this.  By
creating the class beforehand you can minimize the time spent in it
and thereby make the code easier to understand.

    class = Class.new
    class_name = "Foo"
    eval("#{class_name} = class")

-- 
matt