J
Jason Lillywhite
I have a question about the timing of function evaluations in this case:
def function_a(x = 1)
x**2 + x
end
def function_b(any_function)
y = 4 + 5 #this would actually be more complex
function_a(y)
end
puts function_b(function_a)
I found that function_a(x = 1) is evaluated first, then
function_b(function_a). I found that 'def function_a(x = nil) returns an
error. Why does function_a need to be evaluated before it is called as
an argument in function_b?
PS - the reason I am writing things this way is to make function_b
accept any function (within reason).
def function_a(x = 1)
x**2 + x
end
def function_b(any_function)
y = 4 + 5 #this would actually be more complex
function_a(y)
end
puts function_b(function_a)
I found that function_a(x = 1) is evaluated first, then
function_b(function_a). I found that 'def function_a(x = nil) returns an
error. Why does function_a need to be evaluated before it is called as
an argument in function_b?
PS - the reason I am writing things this way is to make function_b
accept any function (within reason).