From: James Edward Gray II Date: 2005-12-07T13:17:35+09:00 Subject: Re: Interfaces in Ruby? On Dec 6, 2005, at 9:03 PM, Gregory Brown wrote: > 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? We generally use respond_to?() for this, but I must stress be REALLY, REALLY sure before you check. Ruby is VERY dynamic. The object may not have the method you ask for until you call it. This is totally normal and okay. I've actually seen people check, so they can throw an Exception if it's not there. Ruby was going to do that anyway. ;) >> Can anyone provide some enlightenment? > > Write proper unit tests so you catch it before it goes out the door :) This is first class advice right here. This should catch type issues and much, much more. The better you get at it, the more you will structure your code for testing (using small methods, for example). That just reduces type issues even further. And you gain so much freedom and power. I promise, when it clicks, you'll never go back. "Free your mind..." ;) James Edward Gray II