~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/psych/lib/psych.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'psych.so'
2
2
require 'psych/nodes'
 
3
require 'psych/streaming'
3
4
require 'psych/visitors'
4
5
require 'psych/handler'
5
6
require 'psych/tree_builder'
6
 
require 'psych/json/tree_builder'
7
7
require 'psych/parser'
8
8
require 'psych/omap'
9
9
require 'psych/set'
10
10
require 'psych/coder'
11
11
require 'psych/core_ext'
12
12
require 'psych/deprecated'
 
13
require 'psych/json'
13
14
 
14
15
###
15
16
# = Overview
89
90
 
90
91
module Psych
91
92
  # The version is Psych you're using
92
 
  VERSION         = '1.0.0'
 
93
  VERSION         = '1.2.1'
93
94
 
94
95
  # The version of libyaml Psych is using
95
96
  LIBYAML_VERSION = Psych.libyaml_version.join '.'
96
97
 
 
98
  class Exception < RuntimeError
 
99
  end
 
100
 
 
101
  autoload :Stream, 'psych/stream'
 
102
 
97
103
  ###
98
104
  # Load +yaml+ in to a Ruby data structure.  If multiple documents are
99
105
  # provided, the object contained in the first document will be returned.
150
156
  end
151
157
 
152
158
  ###
153
 
  # Dump Ruby object +o+ to a YAML string using +options+.
 
159
  # call-seq:
 
160
  #   Psych.dump(o)               -> string of yaml
 
161
  #   Psych.dump(o, options)      -> string of yaml
 
162
  #   Psych.dump(o, io)           -> io object passed in
 
163
  #   Psych.dump(o, io, options)  -> io object passed in
 
164
  #
 
165
  # Dump Ruby object +o+ to a YAML string.  Optional +options+ may be passed in
 
166
  # to control the output format.  If an IO object is passed in, the YAML will
 
167
  # be dumped to that IO object.
154
168
  #
155
169
  # Example:
156
170
  #
 
171
  #   # Dump an array, get back a YAML string
157
172
  #   Psych.dump(['a', 'b'])  # => "---\n- a\n- b\n"
 
173
  #
 
174
  #   # Dump an array to an IO object
 
175
  #   Psych.dump(['a', 'b'], StringIO.new)  # => #<StringIO:0x000001009d0890>
 
176
  #
 
177
  #   # Dump an array with indentation set
 
178
  #   Psych.dump(['a', ['b']], :indentation => 3) # => "---\n- a\n-  - b\n"
 
179
  #
 
180
  #   # Dump an array to an IO with indentation set
 
181
  #   Psych.dump(['a', ['b']], StringIO.new, :indentation => 3)
158
182
  def self.dump o, io = nil, options = {}
159
183
    if Hash === io
160
184
      options = io
163
187
 
164
188
    visitor = Psych::Visitors::YAMLTree.new options
165
189
    visitor << o
166
 
    visitor.tree.to_yaml io
 
190
    visitor.tree.to_yaml io, options
167
191
  end
168
192
 
169
193
  ###