Variable access through self


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

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

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


On 10/31/06, Michael P. Soulier [email protected] wrote:

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

John W.

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. = true
which typically implies something like:

def foo=(foo)
@foo = foo

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 B.
[email protected]