From: John Mair Date: 2010-10-23T03:55:11+09:00 Subject: Re: Why is top-level an object rather than just Object? Thomas Sawyer wrote in post #956386: > On Oct 22, 5: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? > > It should not be. In fact, I think it is a mistake for main to > delegate to Object at all. It becomes a headache when trying to write > a scripting DSL. Rather than run the script at toplevel --which is > very nice b/c of the way #require works, one has to run the script in > a evaluation context so as to prevent pollution of every object. It is > easy enough to extend the Object class by opening it up or opening the > Kernel module, so this delegation is little more than a "nicety" --but > not a very nice one really. > > Ideally main would simply be: > > module Main > extend self > end I can kinda buy that argument, though i can see some problems with it too. Like what would the semantics of 'class Hello' be at top-level then? You'd obviously want it to define a constant on Object or else you'd have to reference Main to get it out. But if you did have the syntax 'class Hello' define a constant on Object then how would you nest class/module constants conveniently? etc. I do kinda like your idea though i just see some difficulties. Nonetheless, back to the original point (if you're interested in commenting on it.) Assuming top-level does maintain its current behaviour, can you see any strong reasons why not to just replace 'main' with Object? since 'main' as been patched and hacked up to act mostly like Object anyway (by messing with cref and default definee and giving it a bunch of class-like singleton methods), what would be the problem in just having the top-level context being Object itself? (forgetting for a minute your objections, but concentrating instead on replicating the current behaviour but with a more elegant model) banister -- Posted via http://www.ruby-forum.com/.