From: Florian Gilcher Date: 2008-05-23T15:33:13+09:00 Subject: Re: Prevent ruby constant variables from changing? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On May 22, 2008, at 6:51 PM, Mark Wilden wrote: > On May 22, 2008, at 4:38 AM, Florian Gilcher wrote: >> >> If you noticed, class names are constants. As you can change >> classes at runtime, constants must be changable. >> Actually overwriting Constants emits a warning. A you should >> program warnings-free, that should be no problem :). > > Sure, you can change classes at runtime, but should you be able to > change which object is referenced by a class name? I haven't heard > of that before. Do you have a real-world example of someone doing > that? Just curious. > > ///ark > "Hot code replace" comes to my mind. Completely reloading a class while keeping the system running. There, it makes sense to completely obliterate the old class. Actually, this is how the RoR class-reloading in development mode works. They clear all loaded application classes so that they are loaded again by the classloader upon need. (via const_missing) About "class name". Yes, #name is just a method. So is #instance_eval and #type and almost every other method. So you could argue that there is no such thing as evaluation in an instance context or a type as language features. On that standpoint, you could argue that there are no classes in ruby, because Ruby only exists of undefinable masses: === class Object def class "undefinable mass" end end === Lets put it like that: In most sane Ruby systems, #name is either the name of the constant a class was bound to or "", the first being named (with a "class name"), the other one anonymous (or call it "ad-hoc", if you prefer). Also, the inability of #name to tell you the internal name of a class doesn't mean that it doesn't have one. This may be a verbal convention and not be enforcemed by the interpreter, but it is a common and reasonable concept. I see no use in oh-so-cool nitpicking that makes it much harder for not-so-zen rubyists to follow discussions. Regards, Florian Gilcher -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkg2ZR8ACgkQJA/zY0IIRZYUNwCfR5r7LiPwdrH4TirnxjxgG6ZU UNgAnih2Bt6gDeWK7i7ss71xxW3F+meT =R5cD -----END PGP SIGNATURE-----