Hi --

On Wed, 24 Aug 2005, Mark Volkmann wrote:

> The way to determine the names of the attributes of objects created
> from a Class, Struct and OpenStruct are all different.
>
> For an object created from a Class you call "instance_variables". I
> wish that method would have been named "attributes".

instance variables are not the same as attributes.  Attributes can be,
and often are, implemented by using instance variables to hold state.
But there is not a one-to-one relation.  Even if you define
"attribute" strictly to mean methods defined with the attr_* family,
there still may be instance variables in use that are not connected
with those methods.

> For an object created from a Struct you call "members". Why not the
> same as the previous case?

There's no connection:

   irb(main):001:0> S = Struct.new("S",:x)
   => Struct::S
   irb(main):002:0> s = S.new
   => #<struct Struct::S x=nil>
   irb(main):003:0> s.x = 1
   => 1
   irb(main):004:0> s.instance_variables
   => []
   irb(main):005:0> s.members
   => ["x"]


Instance variables don't map one-to-one to any higher-level concept
like attributes or members.


David

-- 
David A. Black
dblack / wobblini.net