From: Robert Klemme on
2010/2/18 Claudio Freda <ferdil.kiwi(a)gmail.com>:
> Rob Biedenharn wrote:
>> 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.
>
> Wait, I explain my problem.
> In C++ I would have been able to to this:
>
> void function();
> function();
> void function() {
>  cout<<"The function has been executed"
> }
>
> And it would still print "The function has been executed"

You need that in C / C++ only because implementations are split to
header and source files. We don't do that in Ruby. Instead, we
implement whatever functionality we need and place it in one or more
rb files. Those are then read by using "require".

> In ruby instead if I do this:
>
> def method; end
>
> method
>
> def method
>  print ('The method has been executed')
> end
>
> it just prints me nothing; I think it has something to do with ruby's
> dynamic definitions.
>
> Just how to achieve the same thing in ruby? (summoning a function that
> is declared later in the code)

That's not a problem as long as execution starts later:

def foo
method
end

def method
puts 'It works!'
end

foo

This is typically the case if your required files contain declarations only