On 8/24/05, David A. Black <dblack / wobblini.net> wrote: > 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. I really don't get this. Can you give a definition of each of the terms "instance variable" and "attribute"? I'm pretty sure most people that have been doing OO development for years would say that they thought those were the same thing. Maybe many of us were sleeping in class when those concepts were taught. ;-) Are you saying that instance variables are all the things that start with "@" that have been assigned a value within an object? Are you saying that attributes are implied by the existence of get and perhaps set 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. But conceptually what is the difference between members of a Struct and attributes of an object? And conceptually what is the difference between the members of a Struct and the members of an OpenStruct? Why would their be a different way to discover them? -- R. Mark Volkmann Partner, Object Computing, Inc.