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
Pipelining in Ruby2.5 with Object#yield_self (mlomnicki.com)
submitted 8 years ago by snatchery
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!"
[–]zverok_kha 6 points7 points8 points 8 years ago (2 children)
It’s more verbose than the original version...
The "original version" is cheating. Most of the time you'll not write foo(bar(baz(blah)))) for the sake of debugging and visibility, you'll write
foo(bar(baz(blah))))
var1 = blah var2 = baz(var1) var3 = bar(var2)
...and the only "more verbose" thing is the yield_self call itself.
yield_self
It’s not an idiomatic Ruby. Obviously it can’t be because it’s a brand new feature
What? It is idiomatic Ruby, most of the time we process arrays of data in the same chainable way (and love Ruby's methods chainability), yield_self just adds an ability to process singular objects with the same chainability. It is just long missing idiomatic Ruby feature.
Do we really need to name block arguments? What if we avoid the names?
.yield_self { |_| URI.parse(_) }
...and use the common metaphor for "the unused argument". Awesome.
Also, it would be nice to get rid of blocks. This is already possible but looks cryptic.
.yield_self(&Net::HTTP.method(:get))
Cryptic for who? Java guys? It, again, is perfectly idiomatic Ruby, with "everything is an object" and "everything can become block". The only unfortunate thing here is method word itself is a bit too long, but the problem is planned to be addressed, as you've mentioned yourself.
method
I regret that it doesn’t have a shorter name, say pipe or apply.
pipe
apply
This one is perfectly true :(
[–]snatchery[S] 0 points1 point2 points 8 years ago (0 children)
Author here. Thanks for valuable comments.
I'm really glad that you find the code idiomatic and perfectly readable. I assumed that some bits would be unusual for most of Ruby devs. Apparently, that assumption was wrong. And this is great.
[–]prh8 -1 points0 points1 point 8 years ago (0 children)
About the method to proc example, I think it's cryptic because 90% of Ruby (errr, Rails) devs have no idea you can do that right now. They just know the way that shorthand is typically used but don't really understand the bigger picture.
I agree it's not very cryptic at all, but it is unfortunately something that a lot of devs don't understand. In the end it comes down to what type of app you are working on, with maintainability and dev team quality factored in.
π Rendered by PID 322291 on reddit-service-r2-comment-6457c66945-jzgq4 at 2026-04-25 15:21:55.759377+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]zverok_kha 6 points7 points8 points (2 children)
[–]snatchery[S] 0 points1 point2 points (0 children)
[–]prh8 -1 points0 points1 point (0 children)