Bug #171
closedStringIO#each and StringIO#readlines does change $_, IO#each and IO#readlines do not
Description
=begin
Changeset r17352 has fixed the issue reported in #159, but has introduced two new ones:
First: StringIO#readlines was changed to set $_ to nil:
$_ = "test"
File.open("test.file") { |f| f.readlines } # => ["line 1\n", "line 2\n", "line 3"]
$_ # => "test"
require "stringio"
$_ = "test"
StringIO.new("line 1\nline 2\nline 3").readlines # => ["line 1\n", "line 2\n", "line 3"]
$_ # => nil
Second: StringIO#each was changed to change $_ on each yield:
$_ = "test"
File.open("test.file") do |f|
f.each do |l|
# >> Line: "line 1\n" - "test"
# >> Line: "line 2\n" - "test"
# >> Line: "line 3" - "test"
puts "Line: #{l.inspect} - #{$.inspect}"
end
end
$ # => "test"
require "stringio"
$_ = "test"
strio = StringIO.new("line 1\nline 2\nline 3")
strio.each do |l|
# >> Line: "line 1\n" - "line 1\n"
# >> Line: "line 2\n" - "line 2\n"
# >> Line: "line 3" - "line 3"
puts "Line: #{l.inspect} - #{$.inspect}"
end
$ # => "line 3"
=end