module Psych

def self.safe_dump o, io = nil, options = {}

Psych.dump({a: "b"}, stringify_names: true) # => "---\na: b\n"
# Dump hash with symbol keys as string

Psych.safe_dump(['a', ['b']], StringIO.new, indentation: 3)
# Dump an array to an IO with indentation set

Psych.safe_dump(['a', ['b']], indentation: 3) # => "---\n- a\n- - b\n"
# Dump an array with indentation set

Psych.safe_dump(['a', 'b'], StringIO.new) # => #
# Dump an array to an IO object

Psych.safe_dump(['a', 'b']) # => "---\n- a\n- b\n"
# Dump an array, get back a YAML string

Example:

Default: false.

[:stringify_names] Dump symbol keys in Hash objects as string.

Default: false.

[:header] Write %YAML [version] at the beginning of document.
Default: false.

strictly formal).
[:canonical] Write "canonical" YAML form (very verbose, yet
Default: 0 (meaning "wrap at 81").

For unlimited line width use -1.
[:line_width] Max character to wrap line at.
Default: 2.

otherwise option is ignored.
Acceptable value should be in 0..9 range,
[:indentation] Number of space characters used to indent.

Currently supported options are:

class that isn't in the +permitted_classes+ list.
A Psych::DisallowedClass exception will be raised if the object contains a

Now the Date class can be dumped in addition to the classes listed above.

Psych.safe_dump(yaml, permitted_classes: [Date])

keyword argument. They are additive. For example, to allow Date serialization:
Arbitrary classes can be allowed by adding those classes to the +permitted_classes+

* Hash
* Array
* String
* Float
* Integer
* NilClass
* FalseClass
* TrueClass

classes are allowed to be serialized:
be dumped to that IO object. By default, only the following
to control the output format. If an IO object is passed in, the YAML will
Safely dump Ruby object +o+ to a YAML string. Optional +options+ may be passed in

Psych.safe_dump(o, io, options) -> io object passed in
Psych.safe_dump(o, io) -> io object passed in
Psych.safe_dump(o, options) -> string of yaml
Psych.safe_dump(o) -> string of yaml
call-seq:
##
def self.safe_dump o, io = nil, options = {}
  if Hash === io
    options = io
    io      = nil
  end
  visitor = Psych::Visitors::RestrictedYAMLTree.create options
  visitor << o
  visitor.tree.yaml io, options
end