On Nov 9, 2010, at 17:50 , David Unric wrote:

> Despite of that, if Ruby cann't decide if mymsg is a variable or a 
> method call in advance, how does it rule out the possibility for a 
> static parser to notify the 'mymsg' symbol has no assignment or method efiniton in the source code ? I.e. if 'x' in your example is a method all, how can arise without some form of an assignment ?

I don't entirely understand your question, as "x" in my example is the wrapping method and "mymsg" was the message send from your example.

So let's try again, with the code sample reformatted better:

> % echo 'def x; mymsg; end' | parse_tree_show

begets:

> s(:defn, :x, s(:args),
>  s(:scope,
>    s(:block,
>      s(:call, nil, :mymsg, s(:arglist)))))

read in English: "method definition :x with no args. calls mymsg w/ no args"

So, ruby parsed "def x;" and realized it was a 0 arg method. The body refers to "mymsg;" and since there was no previous variable assignment of the same name, it must be a method call (with no args). That's it. At that point, the method is "compiled" down to a single method invocation for the message "mymsg". Notice I said "message"... that's an important distinction between static and dynamic languages. In static languages (or in dynamic/hybrid languages where the method is pre-calculated), methods/functions are called by having a pointer to the function body and simply jumping to that address.