From: Juergen Strobel Date: 2006-05-13T02:48:43+09:00 Subject: Re: An inherent mismatch when creating dynamic classes On Sat, May 13, 2006 at 12:20:52AM +0900, 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) But dynamically created classes are not constant, so just assign them to a (lowercase initialled) variable and pass it around. It is *you* wanting to assign something dynamically created to a constant that's the problem. Why does your dynamically created class need a constant name? Commonly defined classes are using uppercase because those are really just constants holding an instance of Class, created by magic and syntactic sugar. So it turns out those features are not unrelated at all, and class naming just follows from the constant naming rule. Juergen > >>> 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/. > -- The box said it requires Windows 95 or better so I installed Linux