Short description:
See the patch, the hash passed as argument to recursing
to_xml method is pointing to the same structure as the
original opts hash.
$ rails -v Rails 2.0.2 $ ruby -v ruby 1.8.6 (2007-03-13
patchlevel 0) [i386-netbsdelf]
(rails console) before the patch:
>> print [[], []].to_xml <?xml version="1.0"
encoding="UTF-8"?> <arrays type="array"> <array
type="array"/> <nil-classes type="array"/> </arrays>
=> nil
after the patch:
>> print [[],[]].to_xml <?xml version="1.0"
encoding="UTF-8"?> <arrays type="array"> <array
type="array"/> <array type="array"/> </arrays> =>
nil
Explanation:
After the merge! method on line:
each { |e| e.to_xml(opts.merge({ :skip_instruct => true
})) }
the hash passed to next iteration of to_xml method
is pointing to the same structure as the forcibly merged
opts hash. [1] Then after:
root = options.delete(:root).to_s
this parameter is deleted from the original opts
hash too and to the next iteration are going wrong
opts.
As there is no need to use merge! here because
simple merge returns the same, and we repeat the
merging in each iteration (no need to forcibly change the original
hash), I propose this patch.
[1] It is the same as in this example: $
irb irb(main):001:0> a = {'a' => 1, 'b' => 2} =>
{"a"=>1, "b"=>2} irb(main):002:0> b = {'b' => 3, 'c'
=> 4} => {"b"=>3, "c"=>4} irb(main):003:0> c =
a.merge!(b) => {"a"=>1, "b"=>3, "c"=>4}
irb(main):004:0> a => {"a"=>1, "b"=>3, "c"=>4}
irb(main):005:0> c => {"a"=>1, "b"=>3, "c"=>4}
irb(main):006:0> c.delete('c') => 4 irb(main):007:0> a
=> {"a"=>1, "b"=>3} irb(main):008:0> c =>
{"a"=>1, "b"=>3}