Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes for two IO#gets spec failures.

This patch fixes the following two IO#gets spec failures:

    IO#gets assigns the returned line to $_
    IO#gets returns the entire content if the separator is nil

Signed-off-by: Brian Ford <brixen@gmail.com>
  • Loading branch information...
commit 7f6564b96762d7b3deb9f021789182f5c664a766 1 parent 7aaa704
@cpettitt cpettitt authored brixen committed
Showing with 11 additions and 11 deletions.
  1. +11 −9 kernel/core/io.rb
  2. +0 −2  spec/core/io/.spec/gets_excludes.txt
View
20 kernel/core/io.rb
@@ -119,16 +119,18 @@ def flush
end
def gets(sep=$/)
- cur = read(1)
- return nil unless cur
- out = cur
- until out[-sep.size,sep.size] == sep
- cur = read(1)
- return out unless cur
- out << cur
+ if sep.nil?
+ out = read
+ else
+ out = ''
+ begin
+ cur = read(1)
+ break unless cur
+ out << cur
+ end until out[-sep.size,sep.size] == sep
end
-
- return out
+
+ $_ = (out.nil? || out.empty? ? nil : out)
end
def each(sep=$/)
View
2  spec/core/io/.spec/gets_excludes.txt
@@ -1,3 +1 @@
-IO#gets assigns the returned line to $_
-IO#gets returns the entire content if the separator is nil
IO#gets returns the next paragraph if the separator's length is 0
Please sign in to comment.
Something went wrong with that request. Please try again.