From 5ae604004516bc5944c38eee539b022bd7cf4820 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 29 Sep 2009 20:48:42 -0700 Subject: round trip nil class --- lib/psych.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/psych.rb') diff --git a/lib/psych.rb b/lib/psych.rb index 3ebc1fa..2d0cf0c 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -26,9 +26,23 @@ module Psych parse(yaml).to_ruby end + ### + # Parse a YAML string. Returns the first object of a YAML parse tree def self.parse yaml + yaml_ast(yaml).children.first.children.first + end + + ### + # Parse a YAML string in +yaml+. Returns the AST for the YAML parse tree. + def self.yaml_ast yaml parser = Psych::Parser.new(TreeBuilder.new) parser.parse yaml - parser.handler.root.children.first.children.first + parser.handler.root + end + + ### + # Dump object +o+ to a YAML string + def self.dump o + o.to_yaml end end -- cgit v1.2.3