From: dblack@... Date: 2005-12-29T21:05:15+09:00 Subject: Re: [ANN] (Real) Primitive Ruby Generics support --8323328-1447388271-1135857902=:18432 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1447388271-1135857902=:18432" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1447388271-1135857902=:18432 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Thu, 29 Dec 2005, Isaac Devine wrote: > On Wed, 28 Dec 2005 23:24:01 +0900 > Florian Gro=DF wrote: >>> I have been hacking away to create a simple library that adds >>> generics-like qualities to ruby. At the moment you can define >>> methods with type-matches, defaults if no match and different >>> number of argument matches. >> >> Been there, done that: >> >> http://ruby-contract.rubyforge.org/ >> >> New ideas are very welcome. >> > > Thanks! I've quickly looked at the ruby-doc for that. It's seems to > only be able to specific "contracts" for classes, with method > signatures as a subset. What my goal for generics is to be able to > choose what code to execute based on method/class parameter types. Keep in mind that type !=3D class in Ruby. I think what you're describing is class/module ancestry (the kind of thing you can test with kind_of?) rather than type. Type is, in a sense, circular: an object's type is essentially "the type which is the type of objects which do what this object does". Among other things, that means that for practical purposes objects can be of multiple types. The usual way for objects to identify themselves as suitable for a given purpose is by their type -- that is, by the criterion of what messages they understand. Class membership can give you a likely answer to this, but not a definite one. Depending on kind_of? can also limit your ability to make objects of different classes all converge on a particular capability. It tends to discourage thinking in terms of type and object-centered programming possibilities, including duck typing. Anyway -- you can of course use kind_of? all you like :-) But keep in mind that it's not a type-test. David --=20 David A. Black dblack@wobblini.net "Ruby for Rails", from Manning Publications, coming April 2006! http://www.manning.com/books/black --8323328-1447388271-1135857902=:18432-- --8323328-1447388271-1135857902=:18432--