Ruby builder xml

I am using Builder to create xml in Ruby. It works fine when I call the generate_object method twice. However, when doing it in a loop I am getting some weird results. The input is the same both times. Here is the code.\[code\]def generate_xml xml = Builder::XmlMarkup.new #this doesn't work #objects.each do |o| # generate_object xml, o #end #this works... generate_object(xml, objects[0]) generate_object(xml, objects[1]) enddef generate_object(builder, object) builder.__send__('ins0', :zObjects, 'xsi:type' => "ins1:account") do |a| object.to_hash.each do |k,v| #puts "key #{k} #{v}!!!!!!!!!!!!!!!!!!!" a.__send__('ins1', k.to_s.zuora_camelize.to_sym, v) unless v.nil? end endend\[/code\]Looping through the objects prints:\[code\]<env:Body> <ins0:create> [#<Zuora::Objects::Account:0x007fcd69d61788 @changed_attributes={ "auto_pay"=>nil, "currency"=>nil, "batch"=>nil, "bill_cycle_day"=>nil, "status"=>nil, "payment_term"=>nil, "name"=>nil }, @auto_pay=false, @currency="USD", @batch="Batch1", @bill_cycle_day=1, @status="Draft", @payment_term="Due Upon Receipt", @name="test">, #<Zuora::Objects::Account:0x007fcd69d60d10 @changed_attributes={ "auto_pay"=>nil, "currency"=>nil, "batch"=>nil, "bill_cycle_day"=>nil, "status"=>nil, "payment_term"=>nil, "name"=>nil }, @auto_pay=false, @currency="USD", @batch="Batch1", @bill_cycle_day=1, @status="Draft", @payment_term="Due Upon Receipt", @name="test 2"> ] </ins0:create></env:Body>\[/code\]Executing the two calls without a loop:\[code\]<env:Body> <ins0:create> <ins0:zObjects xsi:type="ins1:account"> <ins1:AutoPay>false</ins1:AutoPay> <ins1:Batch>Batch1</ins1:Batch> <ins1:BillCycleDay>1</ins1:BillCycleDay> <ins1:Currency>USD</ins1:Currency> <ins1:Name>test</ins1:Name> <ins1:PaymentTerm>Due Upon Receipt</ins1:PaymentTerm> <ins1:Status>Draft</ins1:Status> </ins0:zObjects> <ins0:zObjects xsi:type="ins1:account"> <ins1:AutoPay>false</ins1:AutoPay> <ins1:Batch>Batch1</ins1:Batch> <ins1:BillCycleDay>1</ins1:BillCycleDay> <ins1:Currency>USD</ins1:Currency> <ins1:Name>test 2</ins1:Name> <ins1:PaymentTerm>Due Upon Receipt</ins1:PaymentTerm> <ins1:Status>Draft</ins1:Status> </ins0:zObjects> </ins0:create></env:Body>\[/code\]
 
Back
Top