=20
The definition is a definition, the _result of executing it_ is an = instance of class Class.
=20
I agree with you.
=20
You can change a class's properties, e.g. by adding methods etc. It's =
just that the name happens to be a read only property and there is some =
additional magic which will set it on first constant assignment. I =
don't see how that collides with a "purist perspective".
I have not explained my self properly. Imagine we are talking about =
making an instance of any other object e.g. a Car and the car has a name =
and it allows you reference the car instance by it in the future.
Would you prefer the car name is defined by the variable that contains =
it or by setting the name in the constructor?
hotwheels =3D Car.new
current_car =3D Car.new("hotwheels")
I don't think anyone would understand directly that I have automatically =
set a property inside my car with the variable name. It would be a bit =
counterintuitive and different from how any other instance properties =
work on this class and how they are usually set on any other type of =
object of any library.
Considering the Class to be an object too by not allowing me set the =
name at the .new and taking the name of the left hand side of the =
equality sign in case it is a Constant ( otherwise it does not) it is =
not acting very much like any other object.=20
=20
See my posting in this thread from yesterday.
=20
Oh, and btw, that code does not really make sense that way because it = can be easily replaced by
=20
Bar =3D Class.new
=20
or even
=20
class Bar
end
=20
The approach with Object.const_set basically only makes sense if the =
name is dynamic, too.
Yes sorry, I do want to have the name dynamic too ( I might be going =
off-topic for the original post, sorry).
=20
Everything can be done on a low level but usually we define artifacts =
(classes, methods) to group functionality so we can access it more =
conveniently and manage complexity.
=20
=20
I find that wording slightly irritating: it sounds a bit as if you =
assume the class is somehow in the constant. In Reality the constant =
just references the class instance. There is no particular magic =
involved other than the custom syntax with "class Name...end".
Agreed, its just a reference. But if I want to have a dynamic name =
without having to use eval I need to understand that the list of classes =
defined are referred to as constants in the Object and I can do that =
with
Object.const_set("Bar",Class.new)
I am just saying it would be nicer to do Class.new("Bar") would be much =
more like any other object instantiation and less questioned about as it =
would not be an exception to how the rest of the stuff works ( although =
Class object is truly a bit of an exception and its one of those =
marvelous things ruby allows us to tinker with ).=20
=20
=20
I am not sure what you mean by "too much internals". After all, I =
would consider doing
By "too much internals" I mean that I actually need to get to know that =
the class Names are referenced in a list of constants in Object and that =
I can do Object.const_set("Bar",Class.new) to create a class with a =
dynamic name ( and not have to use eval) instead of Class.new("Bar"). =
( Sorry for going in circles)
=20
Foo =3D Class.new do
def x;123;end
end
=20
more bare metal than
=20
class Foo
def x;123;end
end
=20
Syntax with "class" certainly helps makes things a bit more abstract =
and less "internal". What would be the cleaner, more abstract way?
For a definition with a set name totally agree with you.=20
Many thanks for the healthy discussion
Cheers
Vicente