From: Martin DeMello Date: 2007-03-17T04:12:46+09:00 Subject: Re: attr_protected macro On 3/16/07, gaurav bagga 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. Code within a class Foo/end block is executed in the scope of the class Foo. Thus def method..end is actual code that defines a method and adds it to the class, etc. Some methods, loosely called 'macros', define other methods on the fly when they're executed, or do other things commonly lumped under "metaprogramming". For instance, in the following code class Foo attr_accessor :bar end attr_accessor is a method (of the Class class, to be precise), to which the argument :bar is passed. When executed, it generates the following two methods def bar @bar end def bar=(x) @bar = x end Not sure exactly what attr_protected does, but it's somewhere along the same lines. martin