diff options
Diffstat (limited to 'lib/psych.rb')
-rw-r--r-- | lib/psych.rb | 16 |
1 files changed, 15 insertions, 1 deletions
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 |