From: daz Date: 2005-11-10T05:42:13+09:00 Subject: Re: to which object does the global scope belong? Daniel Sch�le wrote: > > irb(main):004:0* def foobar;"foobar";end > [...] > I was wondering in what object scope is the function foobar > defined? > I supposed it would be in > > irb(main):037:0> Kernel.singleton_methods.grep /foo/ > => [] > irb(main):038:0> Object.singleton_methods.grep /foo/ > => [] > irb(main):039:0> > It's defined as a private method of the Kernel module. When mixed-in to class Object, it is an instance method. Then it's (almost) everywhere. def foobar;"foobar";end p Kernel.private_methods.grep(/foo/) # ["foobar"] p Kernel.private_instance_methods(false).grep(/foo/) # [] # (Modules don't have instances) p Object.private_methods.grep(/foo/) # ["foobar"] p Object.private_instance_methods(false).grep(/foo/) # ["foobar"] daz