Dave Thomas wrote:
> 
> "Makhno" <mak / imakhno.freeserve.co.uk> writes:
> 
> > I was wondering if it possible to obtain a reference to a function before it
> > has been
> > 'def'ined?
> 
> Sort of...
> 
> The reference to a function is by name, not by function pointer, so
> you can use the name before the function exists:
> 
>    fn = case ARGV[0]
>         when "clear"
>              :doClear
>         when "reset"
>              :doReset
>         else
>              :doError
>         end
> 
>  However the function must be defined before you can call it:
> 
> #    self.method(fn).call    # this would be an error
> 
>     def doClear
>       puts "Clear"
>     end
>     def doReset
>       puts "Reset"
>     end
>     def doError
>       puts "Error"
>     end
> 
>     self.method(fn).call     # This is OK
> 
> Regards
> 
> Dave

One way to help yourself think top-down, if you want to:

-----------------------
  #!/usr/local/bin/ruby

  def main
    # Top level code goes here....
    print succ(99),"\n"
  end

  # Support code goes here: functions, classes,
  # whatever, arranged in any convenient order....
  def succ(x)
    x+1
  end

  main
-----------------------

  Mark