This looks like a mismatch between two unrelated features (true,
assigning to constants dynamically is fishy, but creating new classes
isn’t !), right ?
And why the class name ‘Bobik’ is printed, while #Class:0x2c17010 is
printed when the class name is in lowercase. Does the lowercase change
anything semantically ?
This method is superfluous. You can simply do “bobik = Class.new” in
this method:
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.
And why the class name ‘Bobik’ is printed, while #Class:0x2c17010 is
printed when the class name is in lowercase. Does the lowercase change
anything semantically ?
Uppercase names are constants and this involves some magic. Consider:
c = Class.new
=> #Class:0x829f4b0
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.
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)
On Sat, May 13, 2006 at 12:20:52AM +0900, Eli B. wrote:
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.
Why does your dynamically created class need a constant name?
Exactly! Thanks for voicing my concerns much better than I did.
Adding to that, what’s the use of a class name of a dynmic created
class? The name won’t be known to other parts of the code beforehand
so it cannot be used for referencing the class.
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.