matz / ruby-lang.org (Yukihiro Matsumoto) wrote in message news:<1006960599.866398.12182.nullmailer / ev.netlab.jp>...
[...]
> There's one more thing I can tell you.  "type" in Ruby is just an
> illusion.  It doesn't really exist, but in our mind.  We emulate it
> sometimes using a class of an instance, sometimes using set of methods
> that an instance can respond.
> 
> If it is merely an illusion, why should we care that much?

I think I agree that the concept of type isn't too much useful in
Ruby, and certainly not as useful as in statically-typed languages. 
Since we can dynamically add methods to classes and singleton methods
to objects, boundaries enclosing "types" can be highly blurred
(methods come and go, etc.).  There's no guarantee that two objects
created by the same class behave alike.  Rather, Ruby code relies on
what methods each object responds to, not on which type it belongs to.
 In this sense, methods in Ruby are inherently generic (like---but
much cleaner than---the STL algorithms in C++).  This is the reason
why you call types illusions, I presume.

That said, programmers (even Ruby programmers) seem to sometimes find
the "illusion" of type more or less useful.  We talk about reading
Strings from a File and converting them to Integers.  We know that *by
default* an object created by class String responds to a well-defined
set of methods and we know well how those methods behave (by default).
 I think we need these rather solid components as concrete building
blocks (pun intended :-) of our programs.  Although OO makes it easy
and pleasant to write abstract, generic code, we also need concrete
code that does "dirty" jobs and concrete data to plug into the
abstract code.  I think this is the reason why many people are
reluctant to dynamically modify Ruby's basic components such as
String.  That is, we often wish to use them more or less as objects
belonging to certain well-defined types.  Otherwise, it would be
extremely difficult to write "dirty" code that does real jobs (reading
data from file, comparing strings and numbers, etc.).  My original
problem of String#== arose from my mistake in this type of concrete
code where I actually needed to compare Strings against Strings,
nothing other.

In higher-level, generic code, the concept of type tends to be much
less useful.  This much I agree.

Thanks for your comments,
Ryo