I want to store a file as /a/b/c/d.txt, but I do not know if any of these directories exist and need to recursively create them if necessary. How can one do this in ruby?
Use mkdir_p:
FileUtils.mkdir_p '/a/b/c'
The _p is a unix holdover for parent/path you can also use the alias mkpath if that makes more sense for you.
_p
FileUtils.mkpath '/a/b/c'
In Ruby 1.9 FileUtils was removed from the core, so you'll have to require 'fileutils'.
require 'fileutils'