Io foreach

Fixes 19 failures, and 8 errors for the spec core/io/foreach_spec.rb, don't change the behaviour of 1.8 and also refactor the common code between IO.readlines and IO.foreach. The remaning  2 failures and 1error are due to IO.popen, and enconding.