Methods are implicit exception blocks, so it's possible to rescue
/ensure
from them without a begin
block:
def file_contents(path)
File.read path
rescue Errno::ENOENT
""
end
def with_lock
mutex = Mutex.new
mutex.lock
yield
ensure
mutex.unlock
end
From @resetexistence and the Berkshelf code base.