2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-19 03:25:44 +00:00

add note on ruby -l switch

Quite a useful switch for one-liners
This commit is contained in:
Dmitriy Non 2019-10-15 09:55:32 +01:00 committed by GitHub
parent ed061663ba
commit 10313bda28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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