Project

General

Profile

Actions

Bug #18892

closed

ARGF.lineno starts from 2 when the file has shebang

Added by znz (Kazuhiro NISHIYAMA) about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [aarch64-linux], ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [aarch64-linux]
[ruby-core:109116]

Description

Since ruby 3.0, ARGF.lineno starts from 2 if the file has shebang.

Following example has #!/usr/bin/env ruby, and it can reproduce with the file has #! only.

$ cat f.rb
#!/usr/bin/env ruby
ARGF.each do
  p ARGF.lineno
  exit
end
$ RBENV_VERSION=3.1.2 ruby -v f.rb f.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [aarch64-linux]
2
$ RBENV_VERSION=3.0.4 ruby -v f.rb f.rb
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [aarch64-linux]
2
$ RBENV_VERSION=2.7.6 ruby -v f.rb f.rb
ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [aarch64-linux]
1
Actions #1

Updated by nobu (Nobuyoshi Nakada) about 1 month ago

  • Status changed from Open to Closed

Applied in changeset git|cd948429223223f5e299626a4695ab30e43de2ea.


[Bug #18892] Reset ARGF.lineno after reading shebang

Actions

Also available in: Atom PDF