I have following output available in a variable test
#<someobject customer=[#<someobject product=[#<someobject id='ABC123'>, #<someobject id=''>], id='ADE343'>]>
I am trying to convert its result as follows:
#<someobject customer=[#<someobject product=['ABC123','DEF143'], id='ADE343'>]>
I can achieve that using following but looks like overkill
test1 = test.customer.map { |p| p.product }.flatten.map { |e| e.id }
test.customer.map { |p| p.product = test1 }
test
Is there any better way to do this?
customer.productreturned an array of product objects I think but now you want it to return an array of strings?initializethe only method), in part so we can test?