From: Justin Collins Date: 2006-07-26T05:03:21+09:00 Subject: Re: "Self" confusion Leslie Viljoen wrote: > Can someone explain why the following produces different results? In > another question I wrote that by default, programs run inside the > definition-space of Object, but now I think that I was wrong: > > class Yoghurt > def self.a > "yoghurt self" > end > def Yoghurt.a > "yoghurt" > end > > p Yoghurt.a > p self.a > end > > > def self.a > "object self" > end > def Object.a > "object" > end > > p Object.a > p self.a > > ------------------------Output: > "yoghurt self" > "yoghurt self" > "object" > "object self" > Really? Because I get: "yoghurt" "yoghurt" "object" "object self" :) I thought the top-level stuff rain inside an instance of Object? Try: p Object.class #=> Class, naturally p self.class #=> Object class A p self.class #=> Class end a = A.new class< Class end So, if we were really in the definition space of Object, then self.class would be class, not Object. -Justin