From: Robert Dober Date: 2010-10-23T05:20:30+09:00 Subject: Re: Why is top-level an object rather than just Object? On Fri, Oct 22, 2010 at 8:28 PM, John Mair wrote: > Robert Dober wrote in post #956378: >> 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. > > Err, how exactly is it a disaster? can you explain? I can see no harm > coming from it. If you can see harm - then explain exactly what harm you > see rather than just communicating a vague sense of foreboding....hehe > ; I believe that Tom (Intransition) has explained quite well. It is also true that one could find workarounds if the ivars were declared in Object, but it is a conceptional disaster. Furthermore how nice and clean would that be ? module Toplevel extend self end and then Toplevel.instance_eval (or maybe module_eval) of the main script implicitely of course ;). Cheers R. > > John > > -- > 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