2010/8/24 Peter Hickman <peterhickman386 / googlemail.com>:
> I believe it comes from the IO class instead
> http://ruby-doc.org/core/classes/IO.html

Yes, this is true.

Rajarshi, you can make your life a bit simpler by doing

File.foreach(dataFile) do |line|
  puts line
end

If you actually need to open the file and manipulate the File / IO
object directly (e.g. because you want to rewind), you can use the
block form of File.open (or IO.open):

File.open(dataFile, "r") do |fp|
  fp.each_line do |line|
    puts line
  end
end

This ensures the file is properly closed which was not the case in
your original example.  You can find more at

http://blog.rubybestpractices.com/posts/rklemme/001-Using_blocks_for_Robustness.html

And if you want to know the internal workings you can look here

http://blog.rubybestpractices.com/posts/rklemme/002_Writing_Block_Methods.html

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/