rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Add `Enumerator::_Each` interface

Open ParadoxV5 opened this issue 1 year ago • 0 comments

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 _Each already describes the requirement for implementing a class decorated with Enumerable. But an _EnumEach is 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 _MethodName should be restricted to interfaces that implement that method_name minimally. […] If you want to specify that your class implements each "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.

ParadoxV5 avatar Jun 29 '24 04:06 ParadoxV5