On 11/18/05, Eric Hodel <drbrain / segment7.net> wrote: > > On Nov 18, 2005, at 4:09 PM, Dominik Bathon wrote: > > > On Sat, 19 Nov 2005 00:57:28 +0100, Eric Hodel > > <drbrain / segment7.net> wrote: > > > >> On Nov 18, 2005, at 3:22 PM, Dominik Bathon wrote: > >> > >>> Symbol#inspect should return a valid symbol literal, right? > >> > >> Not according to the RDoc: > >> > >> $ ri Object#inspect > >> Returns a string containing a human-readable representation of > >> _obj_. If not overridden, uses the +to_s+ method to generate > >> the > >> string. > > > > Yes, but: > > > > $ ri Symbol#inspect > > Returns the representation of sym as a symbol literal. > > I consider Object#inspect to set the intent of all the #inspect > methods, but this may be an oversight. For many of the other core classes (and definitely all other immediate classes), #inspect returns a representation that is eval'able to get back an equivalent (or the same) object. When possible, I think that is what #inspect should do. I think it is a bug that Symbol#inspect almost does it, but not quite (quotes some cases but not others). I found this problem when doing code generation. For immediate objects, I embedded the value in the code directly by using #inspect. I had to put in a hack for Symbol because of the problem discussed.