From: Matthew Kerwin Date: 2013-04-12T13:38:50+09:00 Subject: Re: using an instance variable inside a method ernie n. wrote in post #1105353: > Why can I access p[6] without the "@" within the class? I've run this > in pry/irb and the p array looks the same regardless how I reference it > - either @p or p. What's up here? `@p` references the instance variable, and bare `p` is a method call. `attr_accessor :p` defines a method called `p` which returns `@p` * Thus, your `p[6]..` code is parsed as a method call `(self.p)[6]..`, which is legal because that method (self.p) exists. --- * note: it also defines a method called `p=` which assigns to `@p`, so you can use `p = []` instead of `@p = []` if you want. C.f. attr_reader and attr_writer http://stackoverflow.com/questions/5046831/why-use-rubys-attr-accessor-attr-reader-and-attr-writer -- Posted via http://www.ruby-forum.com/.