method
dump
v2_6_3 -
Show latest stable
-
0 notes -
Class: Psych
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (38)
- What's this?
dump(o, io = nil, options = {})
public
Dump Ruby object o to a YAML string. Optional options may be passed in to control the output format. If an IO object is passed in, the YAML will be dumped to that IO object.
Currently supported options are:
- :indentation
-
Number of space characters used to indent. Acceptable value should be in 0..9 range, otherwise option is ignored.
Default: 2.
- :line_width
-
Max character to wrap line at.
Default: 0 (meaning “wrap at 81”).
- :canonical
-
Write “canonical” YAML form (very verbose, yet strictly formal).
Default: false.
- :header
-
Write %YAML [version] at the beginning of document.
Default: false.
Example:
# Dump an array, get back a YAML string Psych.dump(['a', 'b']) # => "---\n- a\n- b\n" # Dump an array to an IO object Psych.dump(['a', 'b'], StringIO.new) # => #<StringIO:0x000001009d0890> # Dump an array with indentation set Psych.dump(['a', ['b']], indentation: 3) # => "---\n- a\n- - b\n" # Dump an array to an IO with indentation set Psych.dump(['a', ['b']], StringIO.new, indentation: 3)