From: Chris Gardner Date: 2009-02-27T04:59:53+09:00 Subject: Re: Instance Variable Names Available from Class? What I mean is that I would like to ask a class for the names of instance variables of its objects, which may have yet to be instantiated. class Foo def intialize(bar, baz) @bar = bar @baz = baz end end I was trying to ask class Foo for the names @bar and @baz. I've found out that these are accessible only through Foo instances. I'm a Ruby newbie and am just today learning about Ruby's approach to metaprogramming. Brian Candler wrote: > Chris Gardner wrote: >> In metaprogramming, I know how to get the instance variable names from >> an Object (through instance_variables). Is there a way to get them from >> a Class? > > A class *is* an object, with its own instance variables, and you can see > them in the same way: > > class Foo > @bar = 123 > > def self.flurble > @bar > end > end > > p Foo.instance_variables # ["@bar"] > > p Foo.flurble # 123 > > Or did you mean something else? -- Posted via http://www.ruby-forum.com/.