WRT forward references. My code was just

foo(100)

def foo(p)
puts p
end


this will not work unless the call to foo is placed after the function
definition.

Whereas in Javascript that would compile.

I can see that functions can forward reference, so I guess the logical
reason for this is, as you say, that Ruby wants to be able to resolve
as it executes, therefore

p = proc {foo(100)}

def foo(p)
puts p
end

p.call


will also compile, although foo() is a forward reference, because we
don't attempt to execute the call to foo until after Ruby has parsed
the function