On 28/12/05, Steve Litt <slitt / earthlink.net> wrote:
> Oh, I get it!!!
> In see itwould be some_call(&@my_variable), and in ruby it's
> some_call(:my_variable). One thing -- why not some_call(:@my_variable)?

No.

There is nothing even remotely close in C, C++, or Java.

In Ruby, it's *not* some_call(:my_variable), it's some_call(:my_name).



When you do:

   attr_accessor :my_name

You do NOT get a @my_name variable. You get two methods: Foo#my_name
and Foo#my_name= -- that's it. Consider:

>> class Foo
>>   attr_accessor :bar
>> end
=> nil
>> baz = Foo.new
=> #<Foo:0x2d8aea8>

Note. Thus far, there's no instance variable @bar on the Foo instance baz.

>> Foo.instance_methods(false)
=> ["bar", "bar="]

There's our instance methods.

>> baz.bar = 32
=> 32
>> baz
=> #<Foo:0x2d8aea8 @bar=32>

Now that we've called Foo#bar= on the baz instance of Foo class, baz
finally has a @bar instance variable. But not a moment before, unless
we instantiate such an instance variable prior to the call of
Foo#bar=.

So :bar is a name (Symbol) used to refer to the name :bar. It is used
by attr_accessor to create two methods that also operate on a
like-named instance variable. But :bar doesn't refer to a variable,
which is precisely why it isn't :@bar -- you're not creating a
variable @bar, you're creating instance methods #bar and #bar= that
happen to work on @bar in the instance.

-austin
--
Austin Ziegler * halostatue / gmail.com
               * Alternate: austin / halostatue.ca