Then you'd be asking if the object _acts like_ (quacks like) an
enumerable, would you not? Why wrap that in a begin....rescue clause
and only spot it after the fact when you can catch it ahead of time?
Certainly it doesn't violate duck-typing to ask what an object acts
like (which is what imposing conditions on an object would be doing)?!
As Simen Edvardsen says, preconditions or exception handling can
change the location of the error reported so that you're not sure
whether you're dealing with the error at the right location or not.
There are good reasons for having both, but they're *additional*
techniques that can be used.
But I didn't say anything about wrapping #<< calls in a
begin/rescue/end clause. I didn't ask whether the object acts like an
enumerable (because, in fact, I don't care if it's enumerable or not).
I just told it #<< with some arguments. If it doesn't actually
understand #<<, it's going to break -- and that means someone gave me
an object that doesn't work like it is supposed to, or I transformed
the object in a negative way.
When one is duck typing, one is applying a concept, not formalizing an
interface. Ducktator is many things, but it isn't an "implementation
of duck-typing". By definition, there can be no implementation of a
duck type validator -- it's not something that is able to be
statically defined at any point.
-austin