File.open("filename", "r") do |file|
file.each_line do |line|
# do something with the line
end
end
It automatically close the file when it reached the end of the file.
If you want to learn more about Ruby block then head over to Darwinweb and read Ruby Blocks as Closure.
No comments:
Post a Comment