From: John Mair Date: 2010-10-23T00:07:05+09:00 Subject: Re: Why is top-level an object rather than just Object? But, for most cases main already behaves like Object: * calling 'include' in main actually includes in Object * defining a method in main actually defines the method on Object * defining a constant in main actually defines the constant on Object The only notable exception, where 'main' acts like itself (that is - as an instance of Object) -- is instance variables. main has its own instance variables independent of Object. But i do not see a good reason not to just define the ivars on Object. See this post: http://banisterfiend.wordpress.com/2010/10/22/what-is-the-ruby-top-level/ John Robert Dober wrote in post #956321: > On Fri, Oct 22, 2010 at 11:51 AM, John Mair wrote: >> Why is it that top-level isn't just the Object class itself? what's the >> rationale behind the 'main' object? > > Well the Object object, happening to be a module too (read class if > you prefer), is the parent of all ( almost all in Ruby 1.9) instances > in a Ruby program. For me it seems quite a good choice to > use an instance of Obejct to represent the top most "self" in a Ruby > program. > It might be an instance of a special class like Toplevel (being a > singleton presumably), I would prefer that, but the actual approach is > a pragmatic one that is quite ok. > > Now talking about your idea of main == Object I fail to see what that > should be good for. It is surely not the role of the (almost in Ruby > 1.9) most general class in Ruby to carry the responsabilities of main. > > Cheers > R -- Posted via http://www.ruby-forum.com/.