diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-12 00:00:12 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-12 00:00:12 +0000 |
commit | 0a60805af583612439750e3ae2e168bf183f6e84 (patch) | |
tree | 49830e33906b3f2dfadd134b402a19ee1ee8d484 /ext/psych | |
parent | 92a7da1900323139bb678dcde62a8c821cf301f9 (diff) | |
download | ruby-0a60805af583612439750e3ae2e168bf183f6e84.tar.gz |
* ext/psych/lib/psych/visitors/to_ruby.rb: merge key values that
contain something besides a hash should be left in tact.
* test/psych/test_merge_keys.rb: test for change
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych')
-rw-r--r-- | ext/psych/lib/psych/visitors/to_ruby.rb | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 725f1f9f5d..9ccf420c34 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -263,28 +263,42 @@ module Psych def revive_hash hash, o @st[o.anchor] = hash if o.anchor - o.children.each_slice(2) { |k,v| + o.children.each_slice(2) { |k,v| key = accept(k) + val = accept(v) if key == '<<' case v when Nodes::Alias - hash.merge! accept(v) + begin + hash.merge! val + rescue TypeError + hash[key] = val + end when Nodes::Sequence - accept(v).reverse_each do |value| - hash.merge! value + begin + h = {} + val.reverse_each do |value| + h.merge! value + end + hash.merge! h + rescue TypeError + hash[key] = val end else - hash[key] = accept(v) + hash[key] = val end else - hash[key] = accept(v) + hash[key] = val end } hash end + def merge_key hash, key, val + end + def revive klass, node s = klass.allocate @st[node.anchor] = s if node.anchor |