# Variable access through self

**URL:** <https://www.ruby-forum.com/t/variable-access-through-self/74636>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:50am UTC](https://www.ruby-forum.com/t/variable-access-through-self/74636 "2006-11-07T10:50:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_PSSoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@Michael\_PSSoulier](https://www.ruby-forum.com/u/Michael_PSSoulier)\
**Post date:** [November 7, 2006, 10:50am UTC](https://www.ruby-forum.com/t/variable-access-through-self/74636/1 "2006-11-07T10:50:54Z")

</div>

Hi,

I’ve seen a lot of examples in Rails code where they’re accessing what  
appear  
to be instance variables from self. Something like

self.foo = true

Now, I’m assuming that you can only access methods this way, so this is  
actually a method call of

self.foo=(true)

Is that right? I’m not always clear on it.

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![Michael\_PSSoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@Michael\_PSSoulier](https://www.ruby-forum.com/u/Michael_PSSoulier)\
**Post date:** [November 7, 2006, 10:50am UTC](https://www.ruby-forum.com/t/variable-access-through-self/74636/2 "2006-11-07T10:50:56Z")

</div>

On 10/31/06, Michael P. Soulier [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is that right? I’m not always clear on it.  
> That is correct.

–  
Regards,  
John W.

> **[John Wilger](http://johnwilger.com)**
>
> The personal website of John Wilger; Dad, Cyclist, Software Developer

---

<div class="post-metadata">

**Author:** ![Michael\_PSSoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@Michael\_PSSoulier](https://www.ruby-forum.com/u/Michael_PSSoulier)\
**Post date:** [November 7, 2006, 10:51am UTC](https://www.ruby-forum.com/t/variable-access-through-self/74636/3 "2006-11-07T10:51:41Z")

</div>

On Nov 1, 2006, at 12:09 AM, John W. wrote:

> > 
> 
> * * *
> 
> Alice came to a fork in the road. “Which road do I take?” she asked.  
> “Where do you want to go?” responded the Cheshire cat.  
> “I don’t know,” Alice answered.  
> “Then,” said the cat, “it doesn’t matter.”
> 
> - Lewis Carrol, Alice in Wonderland

And you’re also apparently a bit confused about what’s really happening.

self.foo = true  
becomes:  
self.foo=(true)  
which typically implies something like:

def foo=(foo)  
@foo = foo  
end

But you probably are more used to seeing something like:

attr\_accessor :foo

which sets up the “def foo;@foo;end” and “def foo=(foo);@foo=foo;end”  
for you.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
