<dblack / candle.superlink.net> wrote in message
news:Pine.LNX.4.44.0208151905140.9567-100000 / candle.superlink.net...
> > Variables starting with @ are visible both inside and outside of
functions.
>
> The only place that happens, I think, is at the "top level" of
> execution.  Otherwise it's like this:
<cut>

Yes - when writing it I was seeking a conclusion - and I didn't really catch
this difference and the subsequent section I wrote deals with relating
static methods to class scope variables.

It somehow seems like a bug because each file can be viewed as a class
definition of the same root level class. This would be consistent except for
the mentioned behaviour.

def Thing.static_show
puts "Static class scope: @a is >#{@a}<"
end

The functions where @a at class scope is visible, are the static class
methods.


   class Thing
     @a = 1
     puts "Class scope: @a is >#{@a}<"

     def show
       puts "Instance scope: @a is >#{@a}<"
     end
   end

def Thing.static_show
puts "Instance scope: @a is >#{@a}<"
end

Thing.new.show
Thing.static_show

=>

Class scope: @a is >1<
Instance scope: @a is ><
Static scope: @a is >1<