On Wed, Apr 04, 2007 at 09:43:14PM +0900, Jamal Soueidan wrote:
> So until I assign something to it, the interpreter would know nothing 
> about what object it is.

No, it's stronger than that.

If you don't assign something to a local variable, then the interpreter
assumes you're not talking about a local variable at all, but a method call.

  foo               # 1. interpreted as 'self.foo' or equivalently 'foo()'
  foo.bar           # 2. interpreted as 'self.foo.bar' or 'foo().bar()'

  foo = "x"

  foo               # 3. now foo is a local variable. This is an expression
                    #    whose value is the objected refered to by foo.
                    #    i.e. the string "x"
  foo.bar           # 4. invokes 'bar' method on the object refered to by 'foo'

That's because both method names and local variable names fall into the same
namespace (alphanumeric names starting with lower case). There's no "$" to
distinguish a variable from a method as there is in Perl or PHP.

Is it a bit clearer now why it's necessary to assign to a variable before
it's treated as a variable?

> When I write attributes in my code:
> attr_assoccer :var
> 
> I assume > then < the interpreter knows only that @var is a object (base 
> class)?

That's something else. You've defined two methods in your class, 'var' and
'var=', which read and assign to instance variable @var respectively.

local variables are just scratch space on the stack. They are not instance
variables on an object.

Brian.