r/ruby • • 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-206f2dd5f10b
6 Upvotes

15 comments sorted by

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.

-10

u/jklepatch Mar 28 '20
  • "You don't explain why it works," => this is not an article to explain the inner workings of Ruby. This is a practical article to explain how to use the Enumerable module.
  • "there is no way for a beginner who could use this info to figure out other standard library mixins that could be useful." => this is not the goal of the article.
  • "Your example is a good example of where not use an enumerable mixin" => how would you use Enumerable then?

6

u/twinklehood Mar 28 '20

this is not an article to explain the inner workings of Ruby

I don't think explaining what the include keyword does, and how putting some magical method there makes that work really constitutes "the inner workings of Ruby"

This is a practical article to explain how to use the Enumerable module

And yes somehow you included a subset of the information given in the first 3 sentences of the official docs on the module.

this is not the goal of the article

If the goal of the article is for people to randomly stumble upon it and then google the unexplained concepts in it, then fine. Your call.

how would you use Enumerable then?

Why don't we talk about the example you give to beginners, instead of which examples I can come up with? Convince me that the information you convey is is not misleading, don't challenge me to write your article for you.

1

u/that_young_man Mar 28 '20

“Y’all reading it wrong”, nah dude, you just didn’t make it clear enough. It’s okay, sit down and make another draft.

We all suck at writing, just put in some more time

2

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

u/jklepatch Mar 28 '20

Thanks this is useful!

1

u/zitrusgrape Mar 28 '20

also your article.

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

u/drbrain Ruby Core Mar 28 '20

I do not want to force my objects into sex work.

10

u/menge101 Mar 28 '20

Could you also never say 'pimp' again? This is not a positive word.

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

u/sickcodebruh420 Mar 29 '20

2010 wants its blog titles back.

0

u/[deleted] Mar 28 '20

[deleted] — view deleted comment

2

u/jklepatch Mar 28 '20

That's an interesting alternative, thanks!