From: Gregory Brown Date: 2005-12-07T12:03:20+09:00 Subject: Re: Interfaces in Ruby? On 12/6/05, Jeff Cohen wrote: > 1. In C# I can write code that can query an object for the interfaces it > implements to find out what I can do with it. (Rarely used but > sometimes a lifesaver). In Ruby I guess I have to use .methods to find > out what methods it implements? You can use Mixins (Modules) and the query the mixins. So if your object includes Comparable or Enumerable, you can be sure it has the methods of these mixins > 2. In C# I can insure that a function is given an object that implements > a certain interface. If I don't, it's a compile-time error and I know > it before I ship it. In Ruby, I won't know if I accidentally pass in > the wrong object until runtime. I might not catch it before I ship the > code. using respond_to? is usually the way you can do this. See the Java / Ruby example below http://www.kdedevelopers.org/node/1527 > Can anyone provide some enlightenment? Write proper unit tests so you catch it before it goes out the door :) HTH, Greg