3 ms·
Are you coming from java? That's my background (at least one of them), and felt that way too. Interface === API contract == safe. But that really isn't the onl
by mceachen 13y ago
Are you coming from java? That's my background (at least one of them), and felt that way too. Interface === API contract == safe.
But that really isn't the only way to do things. Read up on http://en.wikipedia.org/wiki/Duck_typing http://en.wikipedia.org/wiki/Duck_typing
- innguest 13y agoExactly, you got it. is_a? and respond_to? are code smells.
- dragonwriter 13y ago> Are you coming from java? Well, java was one of the languages I used before Ruby, but I've done more Ruby than Java. > Read up on http://en.wikipedia.org/wiki/Duck_typing http://en.wikipedia.org/wiki/Duck_typing I am well aware of duck typing, and rarely use either #is_a? or #respond_to? That doesn't change that, if you have a reason to use that type of inquiry to check interfaces, #is_a? is the more safe of the two (more likely to reject an object that provides the semantics of concern and less likely to accept one that does not) and #respond_to? is the less safe (more likely to accept an object that does not provide the semantics of concern and less likely to reject one that does.)