Created
June 30, 2012 18:25
-
-
Save Haroperi/3024941 to your computer and use it in GitHub Desktop.
動的言語でファイルのcloseをデストラクタにまかせる場合のちょっとした落とし穴
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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