diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-22 19:51:10 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-22 19:51:10 -0700 |
commit | 3e0c5df3134f2a28822c267aa55916322750b42a (patch) | |
tree | 26fe3d6b9028f3f1e33ff2862c7ed2481708deea /lib | |
parent | 4110ae48f57b1eaa6e8caeffaf5a70f1e32f6973 (diff) | |
download | psych-3e0c5df3134f2a28822c267aa55916322750b42a.zip |
fixing and deprecating load_documents
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index b7e5545..9dfc26e 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -166,12 +166,16 @@ module Psych end ### - # Load multiple documents given in +yaml+, yielding each document to - # the block provided. + # Load multiple documents given in +yaml+. Returns the parsed documents + # as a list. For example: + # + # Psych.load_documents("--- foo\n...\n--- bar\n...") # => ['foo', 'bar'] + # def self.load_documents yaml, &block - yaml_ast(yaml).children.each do |child| - block.call child.to_ruby - end + list = yaml_ast(yaml).children.map { |child| child.to_ruby } + return list unless block_given? + warn "#{caller[0]}: calling load_documents with a block is deprecated" + list.each(&block) end ### |