[Rails] [ANN] "Ruby for Rails" now available in PDF!

dblack@wobblini.net
Tue, 18 Apr 2006 03:30:26 -0000

Hi --

On Mon, 17 Apr 2006, Ken Kousen wrote:

> 3. If you declare an attribute outside a method (the way you normally do in
> Java), you''re actually creating an attribute of the _class_ (i.e.,
a static
> attribute) rather than of an instance attribute.  You need to create
> instance attributes inside a method.  Outside a method, "self" is
the Class
> (!).

I think you mean instance variables here, rather than attributes.
Attributes are kind of second-order constructs layered on top of
instance variables (i.e., when you do attr_reader and related methods,
the attribute methods Ruby generates are implemented using instance
variables).  But the instance variables themselves are not attributes;
they can be used for different purposes.

Maybe this makes it less of a ''gotcha'', in the sense that
instance
variables can be understood incrementally from local variables (plus
the "self" concept), and then attributes are built on top of that.


David

--
David A. Black (dblack@wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" PDF now on sale!  http://www.manning.com/black
Paper version coming in early May!