On Feb 27, 2011, at 3:00 PM, Abinoam Jr. wrote:
> a =3D :prepare_b
> b =3D :prepare_b
>=20
> With Symbol, if it has the same value, it's the SAME Symbol, not =
different ones.

Don't get hung up on using the default new/initialize framework.  You =
can define your own constructors that return existing instances instead =
of allocating a new instance if you want to model 'value' semantics.

message =3D Message.find_or_create('message_a', other, args)

Then define find_or_create such that it manages a cached collection of =
messages that it can dip into if it finds a match or it can create a new =
message if necessary.

In general I think it is better to define your own constructors if the =
'normal' semantics of new/initialize aren't what you want instead of =
redefining new.  You can always make new private if you want to 'force' =
the use of your own constructors.

If the only attribute of your messages is their unique name, then =
symbols might be exactly what you need but be aware that symbols are =
generally not garbage collected so that if you create them based on =
external data you might be opening yourself to a memory exhaustion =
attack (i.e. the attacker can cause your memory footprint to grow =
without bounds). Whether this is a concern or not just depends on where =
the external data is coming from.

Gary Wright=