Skip to content

Maintain $. and $_ across the IO#gets line-reader family - #520

Merged
tannevaled merged 1 commit into
mainfrom
feat/io-gets-globals
Aug 31, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/io-gets-globals

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

IO#gets / #readline advanced the IOObj's own #lineno but never updated the $. (line number) and $_ (last read line) globals, so a spec or program inspecting them after a read saw the stale value.

Now (verified byte-for-byte against MRI Ruby 4.0.6):

  • gets and readline set both $. and $_ (a StringIO updates them too);
  • reading past the last line clears $_ while $. keeps the final line number;
  • the bulk readers #readlines / #each_line advance $. but leave $_ untouched.

Conformance: core/io/gets_spec 21→26, readline_spec 9→10, each_line_spec 18→19; no regressions. FLOOR 17300 → 17310 (measured total 17351). go test ./... green, native + wasip1/wasm build, gofmt clean, 100% merged coverage.

🤖 Generated with Claude Code

IO#gets / #readline advanced the IOObj's own #lineno but never updated the
$. (line number) and $_ (last read line) globals, so a spec (or program)
that inspects them after a read saw the stale value. Now gets and readline
set both $. and $_ (a StringIO updates them too, matching MRI); reading
past the last line clears $_ while $. keeps the final number; and the bulk
readers #readlines / #each_line advance $. but leave $_ untouched, as MRI
does.

core/io/gets_spec 21 -> 26, readline_spec 9 -> 10, each_line_spec 18 -> 19,
no regressions. ruby/spec ratchet FLOOR 17300 -> 17310 (measured 17351).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 0495801 into main Aug 31, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/io-gets-globals branch August 31, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant