From: "David A. Black" Date: 2005-07-12T12:20:21+09:00 Subject: Re: class_attr_accessor Hi -- On Tue, 12 Jul 2005, Luke Kanies wrote: > Yeah, that's what I'll be using, since it should work just fine for my > purposes, but I think it's a touch obfuscated. Of course, I've already > admitted to not fully grokking the 'class << self' syntax, so that > doesn't help. It puts you in the scope of an object's singleton class (i.e., the class where those methods reside which are unique to this object). I sometimes wonder whether all the "class << self" examples obscure the fact that this is a general-purpose thing. In case that's the case, here's an example: str = "I am a string" class << str def x puts "method illustrating singleton class" end end at which point you can do: str.x In general, "<< obj" is just a way of telling the "class" keyword that the class you wish to enter has no name, but is the (anonymous) singleton class of obj. You could in fact do: class C # stuff end and then later: class << C attr_reader :whatever end which is another non-"self" example. David -- David A. Black dblack@wobblini.net