Hi --

On Tue, 16 Jul 2002, Hal E. Fulton wrote:

> ----- Original Message -----
> From: "Justin Johnson" <justinj / mobiusent.com>
> Newsgroups: comp.lang.ruby
> To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
> Sent: Monday, July 15, 2002 1:05 PM
> Subject: Execution question
>
>
> > What happens to 'a' in the following case?
> >
> > class Test
> >   a = 1
> >   puts a
> > end
> >
> > When executing 'a' is printed but what is 'a' in this case?
>
[...]
> If I had to give it a name, I would call it a "class-level
> local variable" or a "class-local variable."
>
> It is definitely neither a class variable nor an instance
> variable.
>
> It is not even the ever-weird "class instance variable" (and
> I wish I had a better name for that) which you would get by
> referencing a single-@ name (like @var) *outside* of any
> method but *inside* the class.

I'd still call that an instance variable -- bearing in mind that a
class is an instance of Class (which has helped me find it less weird,
too :-)

[...]

> I didn't really ever stop to think that a class definition
> started a new scope for local variables in this way. But
> apparently it does.
>
> It doesn't seem useful to me... but please, prove me wrong. :)

Hmmm... I can't make a great case, but maybe just for temp variables
in the service of creating non-temp things:

  class Thing
    a = 0
    @@pr = proc { |x| a += x }
    ...
  end

even though said "non-temp things" aren't going to include method
definitions.

> As a side note, if you "reopen" this class, you can't access
> this variable again (arguably making it even less useful -- bug
> or feature?). Apparently it has died and gone to what Matz calls

Feature, I think.  It would be awfully weird to have local variables
suddenly exist when you reopened a class.  (Not that it would be
likely to arise all that often, but still.)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav