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