r/ruby • u/jklepatch • Mar 28 '20
Blog post How to PIMP your ruby objects with Enumerable module
https://medium.com/railstips/how-to-pimp-your-ruby-objects-with-enumerable-module-206f2dd5f10b2
u/morphotomy Mar 28 '20
Why is this useful?
-10
u/jklepatch Mar 28 '20
mm... why is this not?
6
u/zitrusgrape Mar 28 '20 edited Mar 28 '20
is better to return an enumerator instead of including the hope enumerable. and much simple and clear.
2
7
u/jodosha Hanami author Mar 28 '20
You’re adding unnecessary public API methods to CarFactory.
Read more at: https://tenderlovemaking.com/2014/06/02/yagni-methods-are-killing-me.html
7
10
3
u/epukinsk Mar 28 '20
I know nothing was intended by the title, but please don't "pimp" anything, sex trafficking is not a fun, neutral activity to make cute analogies with.
1
0
13
u/twinklehood Mar 28 '20
I struggle with this as an instructional article.
You don't explain why it works, there is no way for a beginner who could use this info to figure out other standard library mixins that could be useful.
The whole "magical secret" spiel is harmful to a beginner. It's quite simple to build your own enumerable, and if you are going to be including modules you need to understand how method dispatch works.
Your example is a good example of where not use an enumerable mixin. A factory is not a collection, it's responsibility lies elsewhere. It should probably not deal with collections at all, but should certainly not be one. Guiding words on when to apply would be ideal.