3 ms·
> but definitely doesn't involve defining a custom `each` method on your class... Author here! Thanks for the feedback. I suspected as much, and was more or l
by softwaredoug 5y ago
> but definitely doesn't involve defining a custom `each` method on your class...
Author here! Thanks for the feedback.
I suspected as much, and was more or less writing it to be illustrative. Though I agree I am bad at Ruby :)
- tinco 5y agoI don't think jrochkind is correct at all, if you want to make a library that has a datastructure that you want to implement custom iteration on, then it is most definitely idiomatic ruby to implement `each` for it. Your article was spot on in my opinion. That said, in the almost 15 years I've been doing Ruby as my preferred programming language, I think I can count the amount of times I implemented a custom `each` method on one, maybe two hands. As an example of how `each` is idiomatic, consider the Enumerable mixin: https://ruby-doc.org/core-3.0.2/Enumerable.html https://ruby-doc.org/core-3.0.2/Enumerable.html if you implement `each` on your class that mixin gives you all those methods (such as select) for free.
- baash05 5y agoYeah.. totally.. 10 years, I've never seen a custom 'each'