M
Mark Bilk
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).
Even if I do define everything before I use it, how could
I write a recursive function, or two mutually recursive
functions?
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)
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).
Even if I do define everything before I use it, how could
I write a recursive function, or two mutually recursive
functions?
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)