Project

General

Profile

Actions

Bug #4225

closed

IO.foreach should only accept string arguments

Added by djberg96 (Daniel Berger) over 14 years ago. Updated about 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin8.11.1]
Backport:
[ruby-core:34004]

Description

It looks like the IO.foreach method doesn't check its argument type first if no block is provided:

fh = File.new('somefile.txt')

IO.foreach(fh.fileno) # Or, IO.foreach(999999999)
=> #<Enumerable::Enumerator:0x110b0d4>

IO.foreach(fh.fileno){ |line| p line }
TypeError: can't convert Fixnum into String

I'd flip these two lines in io.c:

RETURN_ENUMERATOR(self, argc, argv);
SafeStringValue(fname);

Otherwise, what am I enumerating?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0