From: Chris Rhoden Date: 2009-07-24T12:00:24+09:00 Subject: Re: Ruby from C++ (new to both) question --00163630f2c10fca9d046f6ace65 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Steven, C/++ and Ruby are fundamentally different in a few ways, and you have stumbled onto one of the effects of those differences. With C/++, the reason you name those functions before calling them is for something which basically sanity-checks your code before compiling it to a binary. Regardless, when you run a program written with C/++, it has parsed the entire file and the function you wrote at the end of the file are available from the beginning of the execution. This is a gross oversimplification, I know, but I hope that it's sufficiently clear. In Ruby, each line is executed one after the other. So, the short answer is that there is not a way to do what you are saying. Technically, you could def method; end and then redefine the method later, however, a method does not need to be defined for you to define a method which calls it: that is, there is no sanity check to confirm that "variable" knows how to "do_something" in the following code. def method variable.do_something end So this allows you to include all of your libraries at the top of your file and then actually call the methods later. Provided that the method exists at the time that the line is actually executed, you won't run into problems. I hope this makes sense. Welcome to Ruby! I think you'll like it quite a lot. -chris On Thu, Jul 23, 2009 at 6:21 PM, Steven LeBeau wrote: > Hi, > > I'm currently taking a beginning C++ class and learning Ruby on my own. > > One thing I'm curious about (but don't have the vocabulary to articulate it > to a search engine, apparently) is if there's an equivalent to declaring > functions and then defining them later in the file so you don't have to > worry about where the function is in relation to another function that > calls > it (or is called by it). In Ruby, I guess I'm talking about methods rather > than functions, but the same principle: is there a way for method x to call > method y (which appears later on in the program) by having declaration > statements at the top of your program? (I think that time my question may > have made more sense). > > This wasn't addressed on the Ruby webpage on the "Ruby From C and C++" page > as being a "difference" or a "similarity". > > -Steven > > P.S.--I'm new. Hi! > --00163630f2c10fca9d046f6ace65--