From: "Florian Groß" Date: 2006-01-03T04:25:47+09:00 Subject: Re: A question about Ruby main object Antti Karanta wrote: > Is there some logical explanation for this? I understand that this is very > convenient as these methods appear as "stand-alone functions", but taking > it just as "it just is so" breaks the otherwise consistent rules, as > normally you have to define a method in the context of a class for it to be > a method of that class. However, the "main" object is not class Object, nor > is it a class at all: Note that you are not doing def self.method() end. It's just that def method() end at the top level adds the methods to the Kernel module (which is included in Object meaning its methods are available everywhere) instead of raising an exception or adding them to the top level object itself. It's also interesting to see which singleton methods the top level object has: > ruby -e "p methods(false)" > ["include", "private", "to_s", "public"] to_s is so you see "main" when doing p self etc. at the top level. The other three ones are top level versions of the respective instance method of Module. -- http://flgr.0x42.net/