Add `Enumerator::_Each` interface
It is a common pattern for #each to support both yielding to a block and returning an Enumerator when no block given.
I add this interface as a convenience for library classes; it is not a replacement for ::_Each, which does not require no-block support.
soutaro just for clarity, I'm not arguing for a revision of the existing one, but to add a new one. The reasoning is, the current
_Eachalready describes the requirement for implementing a class decorated withEnumerable. But an_EnumEachis common enough (IMO) to warrant defining it as a common interface (as most core and stdlib enumerables already do it). ⸺ https://github.com/ruby/rbs/issues/424#issuecomment-712034447
I put this interface under the Enumerator namespace to represent how it’s a “special” edition.
Regarding why I’m sticking with _Each:
I think
_MethodNameshould be restricted to interfaces that implement thatmethod_nameminimally. […] If you want to specify that your class implementseach"correctly", then yes, you should have these two interfaces and a shorthand might be useful. ⸺ https://github.com/ruby/rbs/issues/424#issuecomment-711449179
- Resolves #424
- more like – necroposts it 😁
- Feel free to continue discussing the design in the issue and leave just the technical details here.