-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 10 July 2001 1:12am, HarryO wrote: > Thanks to Hal and Dave for clearing that up. > > However, this makes me feel even more like the concept of "constant" > doesn't really mean anything and that numbers aren't first-class > objects. > > Note that I can't remember ever even attempting to change the > contents of something I'd defined to be constant in C++, java or > ruby, so I kind of feel like I should shut up at this point :-). It's not so hard to understand if you realize that ALL variables in Ruby are references, and that all a reference is is a pointer that doesn't have a funny syntax with it. Remember, even in C++: const int *p = new int(20); p = new int(25); Now *p == 25, not 20, even though you were pointing to a constant object. The reason? You didn't change the integer that equalled 20, you just threw it away and pointed to a new object with a different value. This is all you are doing in Ruby. p = 20; p.freeze; # 20 can now NEVER be modified p = 25 # but we don't care, we throw it away and point to 25. Even this is fine: p = 20 p.freeze # 20 can now NEVER be modified p += 5 # but + doesn't modify an object, it returns a NEW one. Basically, freeze is probably not what you want--it stops an object from being modified. It doesn't NOT stop a reference from being assigned to point somewhere else. If you want a variable who can only point on place, use a Constant (i.e. variable with capital letter.) - -- Wesley J. Landaker - wjl / mindless.com http://www.landaker.net PGP DSS/DH Key: 0x0F338E07 PGPKey FP: 3AAA 424B B488 198E B68B C0E5 390A BACA 0F33 8E07 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6a (GNU/Linux) Comment: All your base are belong to us. iEYEARECAAYFAjtLDwMACgkQOQq6yg8zjgdiBwCglSEwSJAyXaiK1iQE7xBuml67 /PMAmQGzQLKEoyLnJttye4xdsTznfXOS =Hn5w -----END PGP SIGNATURE-----