From: Garance A Drosehn Date: 2006-03-09T10:24:57+09:00 Subject: Re: globals outside of OO scripting ------=_Part_257_18087707.1141867481526 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 3/8/06, rtilley wrote: > > > OK, say I have this: > > class Thing > > @@class_var =3D "filename" > > def method > @method_var =3D "a_string" > ... > end > > end > > How can I get to these variables outside of the class. class Thing def Thing.get_cvar return @@class_var end def get_mvar return @method_var end end # Elsewhere in your code: puts Thing.get_cvar puts Thing.new.get_mvar - - - - Note that in the case of method-variables, you can use the even easier shorthand of: attr_reader :method_var and then you'd get the value via: puts Thing.new.method_var where '@method_var' would be the name of the instance- variable whose value will be returned by the method named 'method_var'. Also note that you may confuse yourself by thinking of @-variables as "method variables". They are instance variables. The same value is seen by all methods for any given instance of the class. -- Garance Alistair Drosehn =3D drosihn@gmail.com Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA ------=_Part_257_18087707.1141867481526--