summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/psych.rb14
-rw-r--r--test/psych/test_psych.rb5
2 files changed, 10 insertions, 9 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
###
diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb
index de51fc5..1d13056 100644
--- a/test/psych/test_psych.rb
+++ b/test/psych/test_psych.rb
@@ -13,10 +13,7 @@ class TestPsych < MiniTest::Unit::TestCase
end
def test_load_documents
- docs = []
- Psych.load_documents("--- foo\n...\n--- bar\n...") { |doc|
- docs << doc
- }
+ docs = Psych.load_documents("--- foo\n...\n--- bar\n...")
assert_equal %w{ foo bar }, docs
end