On Sunday 06 June 2004 09:11, David Garamond wrote:
>
> What other things characterizes an object behaviour other than its
> class? I know that Ruby allows us to change object e.g. with
> Object#extend or adding singleton methods, but aren't those implemented
> by creating an internal class?

In Ruby, classes can change radically; methods can go from taking one 
parameter to fifteen, the methods can do completely different things, and so 
on.  Therefore, you can't really call a class a "type" because you can't 
depend on a class doing what you expect it to do.

A type would say something like:

All hashes have a method called each_pair that takes no parameters and calls 
the given block once for each key/value pair the hash contains.

Now, for brevity, consider that the entire type description for a Hash.  What 
we have now is a "hash type."  The Hash class itself can still change it's 
methods, including its each_pair method, but if it ever strays from the 
description of a hash type, it is no longer a hash type.

If Hash tagged itself as complying with the "hash type" you could depend on 
certain methods doing certain things and taking a certain number of 
parameters.

You could also tag other classes as complying with the "hash type" and they 
would also behave exactly like the Hash class, without having to derive from 
the Hash class itself.

Voila, Ruby's dynamicism is preserved and you get typing.

	Sean O'Dell