top | item 42574084

(no title)

ryanmjacobs | 1 year ago

Oh that's embarrassing -- you're right, the first example doesn't make sense. Kinda pointless actually haha

I use it for code like this:

  raw = IO.popen(%W[gzip -d -c -- #{path}]){_1.read}
  raw = IO.popen(%W[gzip -d -c], in: pipe){_1.read}
  raw = IO.popen(%W[git status --porcelain -- #{path}]){_1.read}
Useful because it eliminates /bin/sh footguns (e.g. `md5sum hello&world` forking or `~john` expanding), plus you get kernel.spawn() options. `open("| ...)` only made sense for the second example.

Anyway, I find "_1" more eye-pleasing than:

  IO.popen(%W[gzip -d -c #{path}]){|io| io.read}

discuss

order

No comments yet.