Reputation: 81
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?
Upvotes: 2
Views: 68