From: Rob Biedenharn Date: 2010-02-18T23:18:22+09:00 Subject: Re: Method prototypes like C++? // Compiling executables On Feb 18, 2010, at 8:50 AM, Claudio Freda wrote: > Hi, I'm switching from C++ to Ruby, I have a few questions. > > 1. How come there isn't any "method prototype" feature like the > function > prototypes in C++? Like, in c++ I declared just the name of a > funcion at > the beginning of a block of code and then I could put the function > anywhere in the program, so it could be called wherever, without > worrying if it had been fully declared or not. Is this possible? Sure just do it! Methods only need to exist when then are "called" and even then you can use the method_missing hook to define them on the fly if you need to. > > 2. I find it awesome that you needn't compile to view the results of > your code; still, i would like to be able to compile my programs to an > executable file for distribution. Is it possible? Look at JRuby's ability to create .class files for the JVM, but you might want to keep an open mind about whether you *really* need to compile. > > 3. I still don't get how this whole "gems" thing work. In C++ I used > to > load libraries, it seems that in Ruby most of the libraries are loaded > by themselves when needed. When exactly do I need to include other > libraries? It's a way to have multiple versions of libraries on your system. You'll know you need more because something doesn't exist. For example, there are some useful methods on Date that are only available if you "require 'date'" in your code. (Not the best example because that's not a gem, but a standard library, i.e., it comes as part of Ruby.) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com