Your script "violently ends" because FileUtils.cd
throws an exception when the directory does not exist. Because your script does not handle the exception, it exits.
Wrap your code in a begin
-rescue
-block like this to handle the exception:
require 'fileutils'
begin
FileUtils.cd "A/non/existing/directory"
rescue Errno::ENOENT => e
# do things for appropriate error handling
puts e.message
end
The Errno::ENOENT
exception is thrown when the directory change fails. In the rescue
block you may handle the exception (here I just output the error message).