James Britt wrote:
> Hal Fulton wrote:
> 
>> Robert Klemme wrote:
>>
>>> 2006/2/12, Mark Volkmann <r.mark.volkmann / gmail.com>:> On 2/12/06, 
>>> David Vallner <david / vallner.net> wrote:> > D Nede¥ªa 12 FebruáÓ 
>>> 2006 20:45 Mark Volkmann napùÔal:> > > If Struct is a shorthand way 
>>> for creating Classes, why don't objects> > > created from those 
>>> Classes have instance_variables?
>>>
>>>> My issue is that I wanted to think of Struct as an alternate way of> 
>>>> defining a class and that after doing so I could use it like any 
>>>> other> class.
>>>
>>>
>>>
>>> You can.
>>>
>>
>> Well, what if you want to add a new method to the class? That
>> method should have the right to use the instance variables.
> 
> 
> It does, if there are any.
> 
>> But in a Struct there aren't any.
> 
> 
> Must a class have instance variables to be a 'real' class?
> 
> Why does the use of an array or hash, as the sole instance variable, 
> seem (if I'm following this correctly) to disqualify a class as a 'real' 
> class?
> 
>  From the outside, objects simply respond to messages. On the inside, 
> they do stuff when sent a message.  Sometimes the outside and the inside 
> match up (where you get the Ruby version of public properties), but 
> there's no reason they *have* to, and no reason to assume it is the case.
> 
>  obj.foo=x
> 
> should not lead one to think that obj implements an instance var @foo.
> 

It doesn't have to, but it's common practice.

Once I wanted to construct a simple class, so I used Struct. Later I
decided I wanted to add a custom method to it. I discovered then that
the attributes did not correspond to instance variables. I had to
re-write the class instead of using a Struct.

Maybe I didn't have the "right" to expect those instance variables to
exist, but I think it's an understandable mistake.


Hal