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.
fixing the support of new params on IO.foreach
Merged in 987b731. Spec tags removed in b9e1aa4.