Post #2981936
2026-02-15 20:05 UTC
@blinry@chaos.social ruby's irb and python have the same feature with the _ variable!
IRB:
irb(main):001> 5 + 2
=> 7
irb(main):002> _
=> 7
Python also seems to avoid overriding _ when your statement returns None:
>>> 5 + 2
7
>>> _
7
>>> print("hello world")
hello world
>>> _ # still 7!
7
>>> None
>>> _ # still 7!
7
Replies (3)
-
@blinry@chaos.social 2026-02-15 20:07
@ellnix@fosstodon.org Ohh, very cool! I didn't know that!
-
@jer@hachyderm.io 2026-02-15 20:14
@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)
-
@piko@chaos.social 2026-02-15 21:01
@ellnix@fosstodon.org @blinry@chaos.social Whaaaaaat! 🤩