Can anyone provide some clues as to why these two pieces of code are not equivalent? My only thought is that the .open in the latter code portion is not in a block and the file handle is left open.
File.open(file) do |io|
io.each_line do |line|
body_string << line
end
end
and this one
File.open(file).each_line {|line| body_string << line}
Thanks.
File
test.rb:File
f:output of
ruby test.rb f:The only difference is that, when
File.openis given a block, it automatically closes the file handle.HTH