From: matt@... (matt neuburg) Date: 2009-04-10T03:45:07+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). > > s = "abc" > > # gives error: undefined method `f' for main:Object (NoMethodError) > f(s) > > def f(x) > print('f: ', x, "\n") > end > > # works OK > f(s) The fact that everything is executable code, including "module M", "class C", and "def", and that code is executed in the order in which it is encountered, is part of what makes Ruby Ruby. It is used to accomplish many cool things, like modifying modules that already exist. So don't worry, be happy. m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com