5 ms·
Strictly speaking, you're not actually enumerating for a lot of the potential use-cases of enumerable methods. For example, say #reject were implemented:
by burke 15y ago
Strictly speaking, you're not actually enumerating for a lot of the potential use-cases of enumerable methods.
For example, say #reject were implemented:
User.where(admin: true).reject(office: current_user.office)
There are two ways to implement this: One by literally iterating over the result set and filtering it; and Two by adding a projection to the query builder.
In the second case, it is small-e enumerable, but not strictly Enumerable, since Enumerable very explicitly defines each method in terms of #each. That doesn't make sense for a query builder.
It could implement Enumerable and override every single method, but the point a few people are making here and in the post comments is that checking kind_of?(Enumerable) is non-idiomatic. Including modules for semantic meaning is appealing to programmers from certain backgrounds for completely understandable reasons, but simply checking for the presence of the method needed is more clear -- ie. respond_to?(:each) is the intended solution.
TL;DR: Modules aren't Interfaces.