Post #2981938
2026-02-15 20:14 UTC
@ellnix@fosstodon.org @blinry@chaos.social And in ruby itself `$_` is the last value read with `gets` (get string).
Together with the `-n` (or `-p` switch makes it easy to write some command-line one-liners:
$ echo blinry | ruby -pe '$_.upcase!'
BLINRY
(and I'm pretty sure that's inherited from Perl)
Replies (1)
-
@ellnix@fosstodon.org 2026-02-15 20:21
@jer@hachyderm.io @blinry@chaos.social That's a really good one! One liners are well and good, but the real tip is using `$_` when golfing to avoid the chars of saving the output of gets to a variable 😆 There are also a bunch of similar global variables for anyone wanting to go down a rabbit hole, especially relating to regex in ruby: https://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/globalvars.html