Issue #171 has been reported by Arthur Schreiber.

----------------------------------------
Bug #171: StringIO#each and StringIO#readlines does change $_, IO#each and IO#readlines do not
http://redmine.ruby-lang.org/issues/show/171

Author: Arthur Schreiber
Status: Open
Priority: Normal
Assigned to: 
Category: 
Target version: 


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"


----------------------------------------
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://redmine.ruby-lang.org/my/account