> When coding a library that is meant to be reused in other code, is it > a good idea to make it so that the library will react gracefully if > you pass it a type that it wasn't expecting? One option you have is to use the Design By Contract package[1], which would allow you to put type checks (or method availability checks) in the precondition. This way, the user of the library could choose whether or not the type checks are actually performed at run-time. [snip] > That is from cgi.rb. If you try to do this: > > CGI.escapeHTML(nil) > > or pass it anything else that doesn't have a gsub() method, it will > crash but the error message it gives you is not meaningful and > requires actually looking at the code for cgi.rb to figure out what > happened. Yes, if there are any required methods you should certainly document that for your library. Additionally, you could check the availability of required methods (either in a precondition or just at the top of the method) to make sure the methods you need are there. It's not common practice to check the actual type of arguments, only that they support the required methods. [1] http://www.pragmaticprogrammer.com/ruby/downloads/dbc.html Jason Voegele