From: Joel VanderWerf Date: 2009-04-10T02:54:16+09:00 Subject: Re: Calling a Function Before It's Defined Mark Bilk wrote: > I would like to be able to call a function (or a class, > when I get more object-oriented) earlier in the program > file than where I define it. Such a "top-down" layout > seems natural to me. In C I could use a function > prototype for this. If I try it in Ruby, I get an error > (see code below). Two ways: foo BEGIN { def foo; end } or END { foo } def foo; end > Even if I do define everything before I use it, how could > I write a recursive function, or two mutually recursive > functions? Define the two functions before you call either one. No prob. def foo(n); p n; bar(n-1); end def bar(n); foo(n) if n>0; end p bar(3) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407