Brian Candler
3/16/2007 10:03:00 PM
On Sat, Mar 17, 2007 at 04:12:46AM +0900, Martin DeMello wrote:
> On 3/16/07, gaurav bagga <gaurav.v.bagga@gmail.com> wrote:
> >Hi All,
> >
> > I was going through a blog where I found "Do this by calling the
> >attr_protected macro in your model class definition" what do you mean
> >by macro here.
> > Is it a method?
>
> First a bit of background: ruby has no real 'compile' phase; it
> executes code within a source file as it reads it.
Almost. It actually reads in and *parses* the whole file, start to end, and
builds an internal representation of it: the syntax tree. *Then* it runs it.
The parse may fail if your program is has invalid structure (e.g. you don't
have the right number of matching "end" statements), in which case nothing
is executed.
The parse phase is also significant in that this is the point at which a
decision is made as to whether a bare word is a local variable access, or a
method call.
As an example:
if false
x = 3
end
def x
"hello"
end
puts x # nil
The line "x = 3" is never executed. However, any bare "x" from that point
until the end of the scope is then treated as a local variable access,
rather than a method call.
However the parse phase doesn't define classes or methods; this doesn't
happen until the class or method definitions are *executed*.
Regards,
Brian.