From: itsme213 Date: 2004-12-02T02:17:45+09:00 Subject: Re: singleton methods : when are they not permitted? > > Have I not defined a singleton method on a literal? > > You have not. You defined a singleton method on a string instance that > represents the sequence "x". If you like you can view it that way that > the literal "x" is not directly accessible. It just creates a string > instance with sequence "x" every time it is evaluated: Ah. Subtle. Thanks (assuming I've got it!). Would this re-phrasing be the right idea? A literal (I'll use the term 'value' object as a generalization) is a virtual object that you cannot access or manipulate. Every conceivable value object already exists before the first line of your code is run. What you can create, access, and manipulate are instances that represent, by various encodings, references to a given value object. For immediate objects, these referencing instances use encodings that directly share the same object_id. e.g. :a # reference to unique virtual symbol :a :a.object_id == :a.object_id #=> true :a == :a #=> true, obviously For all other value objects, those referencing instances have "==" defined so that references to the same value object compare as identical. "x" # reference to unique virtual string "x" "x".object_id == "x".object_id #=> false "x" == "x" #=> true