From: Brian Candler Date: 2003-07-07T20:11:38+09:00 Subject: Re: trapping compile time errors -- alas On Mon, Jul 07, 2003 at 07:36:42PM +0900, Gerard A.W. Vreeswijk wrote: > On Mon, 7 Jul 2003 18:38:03 +0900, Brian Candler > wrote: > > >No, there cannot be such a solution. > > > >Ruby runs programs by > >(1) parsing the code, and converting to an Annotated Syntax Tree > >(2) running the AST > > > >If step 1 fails, no code will run at all. > > > >Brian. > > > > I am convinced. So Ruby BEGIN differs from Perl BEGIN. Alas I'd say: I'd say Ruby's model is much cleaner. It's very clear which is the parsing stage, and which is the execution stage - and personally I wouldn't want Ruby to attempt to execute any program which it could not even parse! Note that things like 'require' and class definitions don't actually happen until the execution stage either: class Foo def wibble end end # << class Foo does not exist until this point has been RUN a = Foo.new This means you can do conditional creation of classes: if ARGV[0] == "test" class Foo def wibble puts "Testing only" end end else class Foo def wibble puts "Live environment" end end end Foo.new.wibble $ ruby x.rb Live environment $ ruby x.rb test Testing only Regards, Brian.