From: Bill Kelly Date: 2002-12-02T11:52:07+09:00 Subject: Re: class << self (was Re: [FAQ] What do some of Ruby's symbols mean?) Hi Gavin, From: "Gavin Sinclair" > > class Array > > def instancemethod > > [define] > > end > > > > class << self > > def classmethod > > [define] > > end > > end > > end > > > > There's no arcane magic going on here - self is an object of class > > Class, and in this case it has the value Array. > > That, to me, is obfuscated. 'self' is generally understood as the current > instance of the class. Yes! > Therefore, it is only meaningful inside instance methods. Hang on.... let the beauty of Ruby flow through you.... (Heh, sorry - I was considering attempting some corny Star Wars reference, culminating in, 'You've taken your first step into a larger world...' .... but I've out-cornballed myself, and I can't go through with it ;) The beauty here, folding in meta-classes into the mix - and, as I understand it - is: Class, and the definitions thereof, in Ruby, are less of a special case than languages such as C++ or Java. 'self' *is* relevant inside a class definition in Ruby. Think about the possible implications of the interpreter actually executing statements inside a class definition when they occur in the source... irb> class X irb> @@my_self = self # consider executed right now during the definition of 'X' irb> def X.my_self; @@my_self; end irb> end nil irb> X.my_self X irb> X.my_self.class Class irb> X.my_self.methods.include? "my_self" true irb> X.id 22405636 irb> X.my_self.id 22405636 'self' during the definition of class X, is an *instance* of Class. It's the particular instance of Class representing X. . . . Anyway, I'd recommened the section in chapter 19 of Pickaxe, entitled, "What's the Meta?" -- I just re-read it myself and I'd forgotten a bit of it............ Uhhhhhh... hope this helps Regards, Bill