From: George Ogata Date: 2006-12-14T13:51:00+09:00 Subject: Re: openstruct oddity On 12/10/06, Vidar Hokstad wrote: > > George Ogata wrote: > > Along a similar vein, ruby has the notion of the "current class". > > This is like self in that it is defined at any point in your code, but > > there's no short identifier for it. In fact, I can't think of a > > (non-destructive, thread-safe) expression that will return it. But > > this is the class that will gain a new method when you do "def foo". > > The current class (or module - I saw your correction) is in "self" when > you are outside a "def" or . It is just another object (of class > "Class" or "Module" respectively). > > Try this: > > class Foo > p self > p self.class > end > > module Foo > p self > p self.class > end > > If you are inside a "def" then it is "self.class", but in that case > "self.class" will refer to the class of the object you call the method > on, not the class or module the object was defined in. You're correct (well, almost), but that's two expressions... ;-). And ones where you have to know the context up front (statically). It falls short on instance_eval. Inside an instance_eval block, the current module is self's singleton class. But I was just making the point that there is this bit of state that exists on the C-side that isn't so clearly visible on the ruby one. And that was, I think, the source of my confusion until I looked into it.