From: ara.t.howard@... Date: 2006-08-21T23:52:13+09:00 Subject: Re: working around "single-pass" constraint On Mon, 21 Aug 2006, Rich Morin wrote: > I like to order my program code files as follows: > > Initial comment header > require statements, etc. "main" code BEGIN{ method definitions } note that there are also END{} blocks > (e.g., main :-) and invoke it at the end of the file, I > can get around this issue. I also like the fact that it > (a) puts the code at the same level of indentation as the > code in my methods and (b) limits the scope of variables: > > #!/usr/bin/env ruby -w > # > # foo - code formatting demo > > def main > bar > end > > def bar > puts 'Hi!' > end > > main if you take tis to the next step it's really useful class Main def foo end def bar end def run foo and bar end end Main.new(ENV, ARGV).run if $0 == __FILE__ the reason is that it allows your program to be used as a library without polluting the global namespace. regards. -a -- to foster inner awareness, introspection, and reasoning is more efficient than meditation and prayer. - h.h. the 14th dali lama