From 10313bda28698c9fe39642d3446ab12dcc0f6b37 Mon Sep 17 00:00:00 2001 From: Dmitriy Non Date: Tue, 15 Oct 2019 09:55:32 +0100 Subject: [PATCH] add note on ruby -l switch Quite a useful switch for one-liners --- sheets/ruby | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sheets/ruby b/sheets/ruby index b0cc4b0..c6dd248 100644 --- a/sheets/ruby +++ b/sheets/ruby @@ -13,6 +13,10 @@ ruby -e 'puts "Hello world"' # end ruby -ne 'puts $_' file.txt +# Beware that with the -n switch $_ contains newline character in the end. +# With the addition of -l switch each line read has the newline character removed. +ls | ruby -lne 'File.rename($_, $_.upcase)' + # The -p switch acts similarly to -n, in that it loops over each of the lines in the input # after your code has finished, it always prints the value of $_ # Example: replace e with a