------art_257_18087707.1141867481526
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 3/8/06, rtilley <rtilley / vt.edu> wrote:
>
>
> 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.


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     =             drosihn / gmail.com
Senior Systems Programmer               or   gad / FreeBSD.org
Rensselaer Polytechnic Institute;             Troy, NY;  USA

------art_257_18087707.1141867481526--