[問題] Is "ensure" useless?
感覺 ensure 沒有什麼用
最常舉的例子就是處理 IO:
begin
file = open("/tmp/some_file", "w")
# Write to the file.
rescue
# Handle the exceptions.
ensure
file.close # this always happens.
end
但是這樣也行吧:
begin
file = open("/tmp/some_file", "w")
# Write to the file.
rescue
# Handle the exceptions.
end
file.close # this always happens too.
有沒有 ensure 沒有什麼用的八卦?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.246.1
推
03/30 16:37, , 1F
03/30 16:37, 1F
推
03/30 19:37, , 2F
03/30 19:37, 2F
→
03/30 19:41, , 3F
03/30 19:41, 3F
→
03/30 20:31, , 4F
03/30 20:31, 4F
→
03/30 20:33, , 5F
03/30 20:33, 5F
Ruby 近期熱門文章
PTT數位生活區 即時熱門文章