Project

General

Profile

Actions

Bug #18771

closed

IO.foreach/.readlines ignores the 4th positional argument

Added by andrykonchin (Andrew Konchin) about 2 months ago. Updated 17 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:108503]

Description

The IO.readlines method has the following signature:

readlines(name, sep, limit [, getline_args, open_args]) → array

The last arguments getline_args, open_args are accepted as keyword arguments, so there are actually 3 positional arguments - name, sep, and limit.

But if the method is called with any 4th positional argument - then it's just ignored. But I would expect an exception to be raised e.g. "ArgumentError: wrong number of arguments (given 4, expected 1..3)"

File.readlines('file.txt', "\n", 10)
=> ["abc\n", "\n", "def\n"]
File.readlines('file.txt', "\n", 10, {})
=> ["abc\n", "\n", "def\n"]
File.readlines('file.txt', "\n", 10, {chomp: true})
=> ["abc\n", "\n", "def\n"]
File.readlines('file.txt', "\n", 10, false)
=> ["abc\n", "\n", "def\n"]
File.readlines('file.txt', "\n", 10, nil)
=> ["abc\n", "\n", "def\n"]

It's relevant to the IO.foreach method as well.

Expected behavior - an ArgumentError exception to be raised.

Actions #1

Updated by andrykonchin (Andrew Konchin) about 2 months ago

  • Description updated (diff)
  • Subject changed from IO.foreach/.readlines ignores the 4th positioned argument to IO.foreach/.readlines ignores the 4th positional argument
Actions #2

Updated by andrykonchin (Andrew Konchin) about 2 months ago

  • Description updated (diff)

Updated by jeremyevans0 (Jeremy Evans) about 1 month ago

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/5953

Actions #4

Updated by jeremyevans (Jeremy Evans) 17 days ago

  • Status changed from Open to Closed

Applied in changeset git|27eb36596a65d6bca44b4420ca6526175bf1b431.


Stop ignoring 4th positional argument to IO.#{foreach,readlines}

Fixes [Bug #18771]

Actions

Also available in: Atom PDF