From: Robert Dober Date: 2010-10-23T03:17:00+09:00 Subject: Re: Why is top-level an object rather than just Object? On Fri, Oct 22, 2010 at 5:07 PM, John Mair wrote: > But, for most cases main already behaves like Object: > > * calling 'include' in main actually includes in Object true, but I do not think it is a good idea > * defining a method in main actually defines the method on Object false; but as a private method, again I do not think it is a good idea > * defining a constant in main actually defines the constant on Object I buy this one > > 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. finally a good idea ;) > > But i do not see a good reason not to just define the ivars on Object. Oh but I do, why should Object have instance variables of the toplevel, if there are some good metaprogramming reasons to define ivars on Object ... disaster. That all said, I do not really care too much about toplevel as it should not play a major role in any ruby application of consequent size. Cheers Robert > > 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/. > > -- There are worse things than having people misunderstand your work. A worse danger is that you will yourself misunderstand your work. -- Paul Graham