From: djberg96@... Date: 2014-05-17T16:20:38+00:00 Subject: [ruby-core:62641] [ruby-trunk - Bug #4225] IO.foreach should only accept string arguments Issue #4225 has been updated by Daniel Berger. Still happening as of 2.1.2. ---------------------------------------- Bug #4225: IO.foreach should only accept string arguments https://bugs.ruby-lang.org/issues/4225#change-46777 * Author: Daniel Berger * Status: Open * Priority: Normal * Assignee: * Category: core * Target version: * ruby -v: ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin8.11.1] * Backport: ---------------------------------------- =begin 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) => # 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? =end -- https://bugs.ruby-lang.org/