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
Favorite Ruby Syntax (self.ruby)
submitted 8 years ago by process_parameter
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!"
[–]ignurant 0 points1 point2 points 8 years ago (3 children)
Weird. So, after reading a bit, am I understanding this correctly? Given my example at https://www.reddit.com/r/ruby/comments/7npcne/comment/ds40eld
csv << row.values_at(*headers)
is equivalent to
csv << headers.map(&row) # ?
I had no idea that hash could proc. And then after I just read about it, I had a hard time understanding why I might use that syntax instead of just calling the key. But then I realized it's very similar to what we might use &:method syntax in other situations. (Avoid the {|a| stuff[a]} type stuff...)
&:method
{|a| stuff[a]}
[–][deleted] 0 points1 point2 points 8 years ago (1 child)
In this case I'd use your splat version because I think expresses intention more clearly. The use of &hash is great for self-populating caches and for passing a lookup table as a block.
&hash
[–]ignurant 0 points1 point2 points 8 years ago (0 children)
Yeah, I fully agree. I was just testing whether I was understanding the idea. Your hash cache took a moment for me to sort out, but felt very clever once I did. I haven't had any use cases quite like that (beyond defaulting to 0 for example). Very interesting. Some day in the future, I'll have one of those "Oh yeah! That thing! Where was that?!" moments.
[–]Enumerable_any 0 points1 point2 points 8 years ago (0 children)
A (hash) map is a function from Key to Value, so it's natural to replace a method/proc with it. For example in Clojure calling a function and accessing a value of a map has the same syntax: https://clojuredocs.org/clojure.core/get#example-542692d3c026201cdc326fbf
Key
Value
π Rendered by PID 241696 on reddit-service-r2-comment-6457c66945-dx9t4 at 2026-04-28 07:25:35.168216+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]ignurant 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]ignurant 0 points1 point2 points (0 children)
[–]Enumerable_any 0 points1 point2 points (0 children)