diff options
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 ### |