3 ms·
When writing one-off Ruby scripts, I especially like using the single-line unless with Kernel.fail: fail "bad arg" unless dir = ARGV.shift (If you could f
by derefr 8y ago
When writing one-off Ruby scripts, I especially like using the single-line unless with Kernel.fail:
fail "bad arg" unless dir = ARGV.shift
(If you could figure out a way to also stuff that line with a transformation to a Pathname for not-nil results, I'd be in heaven.)
- jitl 8y agoTakes a bit of setup to monkey-patch String, but: class String def to_pn Pathname.new(self) end end fail "bad arg" unless dir = ARGV.shift&.to_pn