From: Steve Klabnik Date: 2011-06-27T02:08:54+09:00 Subject: [ruby-core:37542] [Ruby 1.9 - Bug #3022] What are $. and ARGF.lineno ? Issue #3022 has been updated by Steve Klabnik. Perl actually keeps a separate document to explain these variables, 'Perlvar' http://perldoc.perl.org/perlvar.html ---------------------------------------- Bug #3022: What are $. and ARGF.lineno ? http://redmine.ruby-lang.org/issues/3022 Author: Marc-Andre Lafortune Status: Assigned Priority: Low Assignee: Eric Hodel Category: core Target version: 1.9.x ruby -v: ruby 1.9.2dev (2010-03-03 trunk 26805) [x86_64-darwin10.2.0] =begin 1) $. is not officially documented. This makes it difficult to know if it works as expected or not... The Ruby Prog Language (Flanagan & Matz) states: "The number of the last line read from the current input file. Equivalent to ARGF.lineno." This is not true in trunk, as demonstrated by: $ rubydev -e " ARGF.gets File.open('/etc/passwd'){|f| f.gets; f.gets} p $., ARGF.lineno " /etc/hosts 2 1 What is the "current input file"? Not clear, but it's not thread local, as shown: $ rubydev -e " p $. Thread.new{File.open('/etc/passwd').gets; p $. }.join; p $. " 0 1 1 2) ARGF.lineno does not conform to its doc. The doc states: Returns the current line number of the current file in ARGF. This value can be set manually with ARGF.lineno=. Reading this, I would expect ARGF.lineno to be the same as ARGF.to_io.lineno. That is not the case: rubydev -e 'p "#{ARGF.lineno} #{ARGF.to_io.lineno}" while ARGF.gets' /etc/hosts /etc/passwd "1 1" "2 2" ... "25 1" "26 2" ... 1) Maybe the best definition would be that $. returns the number of line read operations issued, from the last time an IO was read in the current thread? 2) I suggest the documentation of ARGF.lineno be changed to: Returns the current line number of ARGF as a whole. This value can be set manually with ARGF.lineno=. See also [ruby-core:26303] =end -- http://redmine.ruby-lang.org