"Lloyd Zusman" <ljz / asfast.com> schrieb im Newsbeitrag
news:m3wu0l6kpd.fsf / asfast.com...
> Sam McCall <tunah.usenet / tunah.net> writes:
>
> > Lloyd Zusman wrote:
> >> Is there a way to define forward references to functions?  Due to my
own
> >> personal eccentricities, I like to have the main body of a program
> >> appear at the top of its source file, and the functions it uses at the
> >> end.
> > In ruby, function definitions are code that gets executed, rather than
> > declarations that get found in the source file and put into a table.
> > So basically, the definitions have to come before the code that uses
> > them (but not before the definition of the methods that use them) in the
> > program flow. Therefore, if you want the main code at the top of the
> > file, put it in an END block or a method as already mentioned, or in a
> > separate file etc.
> > Defining stubs at the top won't work, because your main code runs before
> > the methods are redefined.
> > Sam
>
> Thank you very much, and thanks to all the rest of you for your helpful
> replies.  Based on all this, I have settled on the following approach,
> which I have mentioned earlier in this thread:
>
>   def main
>     # my main routine
>     #
>     # ... etc. ...
>     #
>     return (exitcode)  ### or this:  exit(exitcode)
>   end
>
>   def function1
>     # ... etc. ...
>   end
>
>   def function2
>     # ... etc. ...
>   end
>
>   # other functions ...
>
>   # final line ...
>   exit(main)

Sorry, but I get the feeling that you are trying to make Ruby similar to C
too much.  IMHO the result is worse than straight ruby code.  Let Ruby be
Ruby and C be C. :-)

Kind regards

    robert