Accessing class instance variable from instance method

David Garamond [mailto:lists@zara.6.isreserved.com] :

>>Is there an easier way other than:
>> class C
>> @var = "class instance"
>> def C.var; @var end
>> def class_instance_var; @var = "instance"; self.class.var; end
>> end
>>
>> p C.new.class_instance_var # -> class_instance

irb(main):001:0> class C
irb(main):002:1> @var = "class instance"
irb(main):003:1> def class_instance_var
irb(main):004:2> self.class.instance_variable_get(:@var)
irb(main):005:2> end
irb(main):006:1> end
=> nil
irb(main):007:0> C.new.class_instance_var
=> "class instance"

-austin

ยทยทยท

--
austin ziegler * austin.ziegler@evault.com