From: Logan Capaldo Date: 2006-03-09T10:23:49+09:00 Subject: Re: globals outside of OO scripting On Mar 8, 2006, at 7:58 PM, rtilley wrote: > gwtmp01@mac.com wrote: >> Much easier just to wrap it all in a trivial class to start with >> as Ara suggested. > > OK, say I have this: > > class Thing > > @@class_var = "filename" > > def method > @method_var = "a_string" > ... > end > > end > > How can I get to these variables outside of the class. > You can't, that's kind of the point. You can write accessors (or setters and getters, whatever terminology you prefer) e.g. class Thing def method_var=(value) @method_var = value end def method_var() @method_var end end To save typing you can use attr_accessor class Thing attr_accessor :method_var end t = Thing.new t.method_var = 3 t.method_var #=> 3