YAML.dump
require 'stringio' require 'yaml' s = StringIO.new YAML.dump(['A list of', 3, :items], s) puts s.string