method

foreach

v1_8_6_287 - Show latest stable - Class: IO
foreach(...)
public

Executes the block for every line in the named I/O port, where lines are separated by sep_string.

   IO.foreach("testfile") {|x| print "GOT ", x }

produces:

   GOT This is line one
   GOT This is line two
   GOT This is line three
   GOT And so on...

1Note

enumerator and number of lines to read

jkroeze ยท Mar 19, 2015

== Example
File.foreach(filename) .take(number_of_lines) .map do |line| # ... stuff ... end