Why do you insist on using is_a? / Kind_of? when is response_to? is a much cleaner way to test things? You want objects to implement an interface / contract without being a subclass of any arbitrarily selected superclass. But maybe I missed some requirement here.
Change I understand your arguments, but this often leads to poor OO / dynamic design. Or you are doing something similar, which might be an acceptable idea in leaf classes, but within the framework you need to solve with inheritance:
if a.is_a?(something) #do something elif a.is_a?(something_else) #do something else ...
or something like this:
if !a.is_a?(something) #raise condition/return null/etc. endif ...
I think that rejecting an error code does not understand the language-based exception for message passing is an ideal design solution.
As an additional problem, using is_a? instead of response_to? limits your ability to use mock objects in unit testing. This can be a pretty big problem even for moderately complex code.
Wojciech bederski
source share