Skip to content

Instantly share code, notes, and snippets.

@Haroperi
Created June 30, 2012 18:25
Show Gist options
  • Save Haroperi/3024941 to your computer and use it in GitHub Desktop.
Save Haroperi/3024941 to your computer and use it in GitHub Desktop.
動的言語でファイルのcloseをデストラクタにまかせる場合のちょっとした落とし穴
# generate a file (1000 lines)
def make_1000lines
f = open("hoge", 'w')
1000.times do |i|
f.puts i.to_s * 100
end
end
make_1000lines()
puts `wc -l hoge` # 989 is printed in my environment.
# when this program is finished, type `wc -l hoge` and you'll get 1000.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment