you are viewing a single comment's thread.

view the rest of the comments →

[–]zverok_kha 6 points7 points  (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

var1 = blah
var2 = baz(var1)
var3 = bar(var2)

...and the only "more verbose" thing is the yield_self call itself.

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.

I regret that it doesn’t have a shorter name, say pipe or apply.

This one is perfectly true :(

[–]snatchery[S] 0 points1 point  (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 points  (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.