From: Claus Spitzer Date: 2004-08-15T04:31:11+09:00 Subject: creating classes on the fly Greetings again! I'm trying to create a user-defined class on the fly. The idea would be for the user to provide a class name, maybe a superclass name, and some method definition as a string, e.g. str1 = "MyClass" str2 = "Class" str3 = "def bar \n p \"bar!\" \n end" and then my program would perhaps do something like eval "class #{str1} < #{str2}\n #{str3} \n end" So far so good. Security is not a concern, this is just for a proof of concept. But I would like to be able to then extend MyClass separately, e.g. module Mod def bar p "foo!" end end class ??? include Mod end I'm stuck on the ??? part. I tried class eval( str1 ) I tried class str.intern # (I think I know by now why this one was a stupid idea) I tried $myclassref = eval str1 class $myclassref All to no avail. So I'm wondering whether I'm trying to do this the wrong way. What would be the Ruby way of solving this problem?