Actions
Bug #4225
closedIO.foreach should only accept string arguments
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin8.11.1]
Backport:
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
Like0
Like0Like0Like0Like0Like0