新版本的变更 / Ruby 2.5

# *** before: ***
def read_old(path)
  File.open(path) do |f|
    begin
      f.read
    rescue Errno::ENOENT
      "missing"
    end
  end
end

# *** in version 2.5: ***
def read(path)
  File.open(path) do |f|
    f.read
  rescue Errno::ENOENT
    "missing"
  else
    # runs only if no exception was raised
  ensure
    puts "closing handled by the block"
  end
end

puts read("no_such_file.txt")