upvote
Could this be elaborated?
reply
ls | grep file.txt vs ls().grep("file.txt")
reply
yeah but chaining is almost ubiquitous - found in js, ruby, python, rust, go, etc
reply
But so are pipes, right? Bash, and the many variants, powershell, nushell... Not to mention the languages that implement them with slightly different symbols (|> in R for example).
reply
Your comparison is not quite optimised as you use () which is not necessary. But I understand the comparison you make.

But, you can write an optimised pipe in ruby too. I actually did that, because I could not want to be bothered to be restricted via ruby's syntax for pipe-like operations.

Even aside from that, the original claim was about pipes versus method chaining. To me these are not orthogonal to one another; they are very similar. Just with the pipe focusing on tying together different programs and focusing on input-output functionality. Method chaining in ruby is a bit more flexible, we have blocks, and usually the methods chained occur in one class/object or the toplevel namespace (less frequently though, usually). Even the pipe comparison is not ideal, because traditional UNIX pipes don't support e. g. data manipulation via an object-oriented focus. And I want that (see avisynth, but extend the idea there via a) nicer syntax and b) data manipulation for EVERYTHING).

I don't see pipe as being exclusive over method chaining or reverse.

One interesting idea was to add |> elixir's pipe-like operator to ruby. I like that, but indeed, the net-gain in ruby is quite minimal since method-chaining + blocks already offer a ton of flexibility, so I am not sure how |> would fit into ruby 1:1. Still I like the idea, but anyone proposing |> needs to come up with really convincing ideas to matz here. Because people WILL ask what the real difference is to method chaining. Even fail-safe method chaining in ruby though I absolutely hate the syntax via ? there ... it reads like garbage to me. Example:

https://github.com/ruby/ruby/blob/trunk/test/ruby/test_threa...

    t1&.kill&.join
(It has moved since then, so the above link no longer works, been some years since I first saw it. Upon seeing it my brain instantly cancelled any use of "&.", even though I understand the rationale. It is just ugly to no ends. I still like the |> syntax in Elixir though, even though I can not really see what this should do in ruby.)
reply
the difference between method chaining and the pipe operator is that method chaining normally only works on methods that are supported by the object being returned, whereas the pipe operator works on any function that can take that object as input. in other words the pipe operator is a lot more flexible and doesn't require me to patch the objects class in order to add support for the function i want to call with it. method chaining syntax works in rubish because it either defines or pretends that all unix commands are methods of some class that represents the output of a command.
reply
I'm coming from the point of view of nushell, or powershell, both of which can be used for data manipulation (tables and objects respectively). I love programming in nushell compared to something like this.
reply
The docs literally says that the () on the first ls is required.
reply
Note that I just elaborated what I thought was being asked. Parantheses - see what switching professionally to Ruby wonderland to Python does to a person! Just in about half a year needed..
reply
Like the other commenter elaborated for me. My mental model of how programs are composed much prefers the pipe symbol rather than chaining. There's also less typing too. But each to their own.

Apparently a number of people disagree with me, or the way I initially expressed myself, judging from the amount of downvotes I've had. Weird how that happens; tabs and spaces.

reply