From: Dave Thomas Date: 2003-03-25T01:45:28+09:00 Subject: Re: Types (was Re: Ruby lecture slides (was Strong advantages over Python)) On Monday, Mar 24, 2003, at 10:32 US/Central, Mark Wilson wrote: > I don't think it is necessary to name the types of 'f' and 'o' but > they can be described by their behavior, which is identical. To the > extent two different classes have different methods, of any number, > they are different types, which types may, but need not be, named if > necessary or convenient. > Except... you're really only interesting in the set of methods that you code needs to send to an object at a particular point: it's the protocol that you require at that point that determines type equivalency, rather that the complete set of methods implemented by an object. For example, say I want to unit test a method that writes to a file. I know it writes using the '<<' operator: def meth(file) file << "hello world" end I could write that test using a String as the receiver: str = "" meth(str) assert_equals("hello world", str) At the point of invocation, String and File don't have identical sets of methods, but they do have sufficient overlap (#<<) for my purposes. They are therefore equivalent types. Cheers Dave