YAML::parse Method
Loads a single document as a YamlNode tree

  (String or IO) io

The string or IO object to read from.
Return Values
A YamlNode object or nil if no document found.


The YAML::parse method loads a single YAML document from a stream into a YamlNode. The YamlNode can be used to apply YPath expressions or validate against a schema structure.

tree = YAML::parse( File.open( "README" ) )
puts tree.type_id
# prints:
#   map

title = tree.select( "/title" )[0]
puts title.value
# prints:
#   YAML.rb

obj_tree = tree.transform
puts obj_tree['title']
# prints:
#   YAML.rb
Ex. 43: Parsing a YAML document

With the YamlNode, you can access data before it's typed and transformed into Ruby native types. A tree of YamlNodes can later be turned into Ruby native types by using the YamlNode#transform method.