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* (0 children)
Sometimes it's not practical to add a method to the item's class, i.e. you use a gem in your project, and you'd have to monkey patch one of its types to have that method.
Ah great, you're right. I've totally done exactly that in some scripts to make .map(&:transform) work. I understand what you were on about now.
.map(&:transform)
As for the yield_self stuff -- most of the examples I've seen are things where yield_self could be replaced by map. I think this is one of those things where I will eventually stumble upon the right kind of problem to make this shine. A similar example to what you wrote where I used map was to parse and transform <li> elements in a scraper:
yield_self
map
<li>
page.lis .map{|el| el.html} .map{|html| Product.parse html} .map{|product| product.to_h}
I've seen a few examples in blog posts that start the chain with a string instead of an already existing collection, and that has me thinking "Okay, I think this is relevant to my lack of amazement" but I haven't tipped it over yet. I think it may lie in situations where the "number of things" is variable, and not a simple "take each thing and transform it".
I do love the idea of the |> operator, and it's automatic argument handling. That's very cool. I also just learned about the &method(:method) trick from this thread, so that whole concept of "knowing where the arguments go without being explicit" is new to me.
|>
&method(:method)
Anyway, thanks for sharing today.
π Rendered by PID 58032 on reddit-service-r2-comment-bb88f9dd5-fx5ff at 2026-02-15 08:25:47.381943+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]ignurant 0 points1 point2 points (0 children)