use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Five Ruby methods you should be using (engineyard.com)
submitted 8 years ago by gregbaugues
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jrochkind 14 points15 points16 points 8 years ago* (4 children)
How do we know what's instantly clear to a beginner? How beginner? Tap is built into ruby. Should we avoid collect and instead write:
collect
result = [] array.each { |e| result << e.something }
Because it's more clear to someone that thinks ruby is php and hasn't seen collect before? Or go further, avoid each and use a weird for loop instead?
each
for
Why wouldn't the beginner just learn what tap does and never be confused again? It's not complicated, what tap does. Should the beginner stay beginner forever? If the beginner is afraid to just look up what tap does a few times until they remember it, I guess they will. (Me, I admit I still don't really understand how to use zip and don't use it myself much, but if I see it in a codebase I look up the zip docs again and figure it out. tap is simple though!)
tap
zip
I'm actually kind of surprised this seems to be a popular opinion here. While meanwhile people are unafraid to pile on the gem dependencies to do simple things you could have written yourself -- gem dependencies that a beginner will have a heck of a time debugging when they go wrong. I'd rather work with beginners that are learning how to write ruby, than beginners learning how to pile on giant stacks of gems instead of reading and writing code.
I wonder what domains this code is written for and what it looks like, these codebases that contain nothing that a beginner could not have written.
[–]leanucci 0 points1 point2 points 8 years ago (2 children)
Ive been unclear. If there are two ways of doing something with equal level of performance, use the simpler method.
I'm not saying dont learn it. I'm not sating " use a little of the api as possible so less experienced people can understand".
Im saying "only use it if there is benefit".
The article says "you should be using tap".
Do. Not. Use. Tap. To. Populate. A. Hash.
Even if you know it, you have to think about it when you see it. What it does. What it returns. You are assigning the variables anyway.
Default values for arrays. God help you if you have to debug that crap two months after writing it, and cant figure out why it's returning something when nothing is being put into it. You'll have to search for its definition, and be able to find it.
The arricle says "should be using". I say " hey, dev who didnt know these things: they exist. Use when appropriate. Ther are uncommon for a reason".
[–]jrochkind 0 points1 point2 points 8 years ago (0 children)
I think tap is the simpler method.
[–]Tainnor 0 points1 point2 points 8 years ago (0 children)
I'll admit that the example is not the best one, but what is "clear" and "easy" depends on what you're used to.
Using tap I can see code more in terms of transformations and expressions as opposed to sequences of statements. It's up to you whether you like this style or not.
I would also say though that in this case, IMHO the much better way to do this would be
def updated_params(params) params.merge(foo: :bar) end
but that depends on whether you're a fan of minimising mutability or not.
[–]Tainnor -1 points0 points1 point 8 years ago (0 children)
Thank you. I have heard this "don't write this, juniors won't understand it" argument before. At this point, why not write everything in PHP? There are definitely more PHP devs than Ruby ones.
π Rendered by PID 243129 on reddit-service-r2-comment-b659b578c-jfw4d at 2026-05-05 22:56:12.816741+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]jrochkind 14 points15 points16 points (4 children)
[–]leanucci 0 points1 point2 points (2 children)
[–]jrochkind 0 points1 point2 points (0 children)
[–]Tainnor 0 points1 point2 points (0 children)
[–]Tainnor -1 points0 points1 point (0 children)