From: Patrick Hurley Date: 2006-05-13T02:26:53+09:00 Subject: Re: An inherent mismatch when creating dynamic classes On 5/12/06, Eli Bendersky wrote: > >> This looks like a mismatch between two unrelated features (true, > >> assigning to constants dynamically is fishy, but creating new classes > >> isn't !), right ? > > > > I don't see the problem. How can unrelated features mismatch? Also: > > Constant assignments are simply not allowed in method bodies. > > IMHO it's a mismatch because when I want to create a class dynamically > in some method, I just want to give it a Name like any other class, > beginning with an uppercase letter. But I can't, because it is > considered a dynamic constant assignment. So I'm forced to name it > against the Ruby convention (or use const_set) > > >>> c = Class.new > > => # > >>> c.name > > => "" > >>> Foo = c > > => Foo > >>> c.name > > => "Foo" > > > > Classes do not have a proper name until assigned a constance. But > > otherwise they are fully functional. No problem with that. > > If that's the only difference, it's OK I guess. > > > -- > Posted via http://www.ruby-forum.com/. > > If you really need to set the constant you can also try something like: Object.const_set("NewClassName", klass_obj) pth