On Mar 27, 2011, at 9:02 PM, Eric Christopherson wrote:

> On Sat, Mar 26, 2011 at 1:16 PM, Vicente Bosch Campos =
<vbosch / gmail.com> wrote:
>> 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.
>>=20
>> Would you prefer the car name is defined by the variable that =
contains it or by setting the name in the constructor?
>>=20
>> hotwheels =3D Car.new
>>=20
>> current_car =3D Car.new("hotwheels")
>>=20
>> 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.
>>=20
>> 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
> Is there a way in Ruby to do this with objects generally (i.e. to
> automatically set a name property upon assignment with =3D), not just
> with Classes?
>=20


I think this Constant "Magic" only works for classes as Robert has =
indicated. At least I have not seen anything on google or my bookshelf =
to do it.

I personally would not use it, its an exception of how the operator =
works, and forces people to delve into how your object works which can =
be considered as not very clean.

For the specific case of the Class and being such a high level =
metaprogramming structure, love Ruby for it, I can understand why Matz =
treated it as something special.