summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-07 23:05:45 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-07 23:05:45 +0000
commit3a185ede69ac5845aebbde38dc8e6fbe4f64308a (patch)
treeccab9d64513867618fef559087c6c2fdcc8de72c /ext/psych/lib/psych.rb
parenta5d37d10a9e18952badcf821679104613590e779 (diff)
* ext/psych/lib/psych/visitors/emitter.rb: sending emit options to
YAML emitter. [ruby-core:28318] * ext/psych/emitter.c: updating documentation about emit options * ext/psych/lib/psych/core_ext.rb: ditto * ext/psych/lib/psych.rb (dump): passing emit options to emitter. * ext/psych/lib/psych/nodes/node.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib/psych.rb')
-rw-r--r--ext/psych/lib/psych.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb
index c1feff8e3a..ba4a683974 100644
--- a/ext/psych/lib/psych.rb
+++ b/ext/psych/lib/psych.rb
@@ -155,11 +155,29 @@ module Psych
end
###
- # Dump Ruby object +o+ to a YAML string using +options+.
+ # call-seq:
+ # Psych.dump(o) -> string of yaml
+ # Psych.dump(o, options) -> string of yaml
+ # Psych.dump(o, io) -> io object passed in
+ # Psych.dump(o, io, options) -> io object passed in
+ #
+ # 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.
#
# 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)
def self.dump o, io = nil, options = {}
if Hash === io
options = io
@@ -168,7 +186,7 @@ module Psych
visitor = Psych::Visitors::YAMLTree.new options
visitor << o
- visitor.tree.to_yaml io
+ visitor.tree.to_yaml io, options
end
###