
Issue #21635 has been updated by kddnewton (Kevin Newton). This is happening because of prism's use of IO#gets on STDIN. We will fix this. ---------------------------------------- Bug #21635: Reading code from STDIN unexpectedly sets $_ in 3.4.6+ https://bugs.ruby-lang.org/issues/21635#change-114829 * Author: sisyphus (Sisyphus P) * Status: Open * Assignee: prism * ruby -v: ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [arm64-darwin23] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- It seems from Ruby 3.4.6+ if you pass in code that doesn't end with a newline to the ruby interpreter it sets `$_`: ``` # ruby -v ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [arm64-darwin23] # printf 'p $_' | ruby "p $_" ``` This only happens if the code passed in doesn't end with a newline and doesn't happen in ruby 3.4.5 or earlier: ``` # ruby -v ruby 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [arm64-darwin23] # printf 'p $_' | ruby nil ``` I would expect that `$_` is nil at the start of program execution. NB. this does result in the world's shortest Ruby quine (`printf 'print' | ruby`) -- https://bugs.ruby-lang.org/