I have following array of hash. I am trying to loop over it and build an array of hash of values of id and product_order_id.
objects =
[
#<Product: 0x00007ffd4a561108
@id="1",
@product_id="2",
@product_order_id="23",
@description="abc",
@status="abcde",
@start_date=nil,
@end_date=nil>,
#<Product: 0x00007ffd4a560c80
@id="45",
@product_id="22",
@product_order_id="87",
@description="ahef",
@status="gesff",
@start_date=nil,
@end_date=nil>
......more objects.....
]
This is what it should look like
[{ "1": "23" }, { "45": "87" }] -->its going to be uuid
I tried doing this but no luck
def mapped_product(objects)
mapping = []
objects.each do |object|
mapping << {
object.product_order_id: object.id
}
end
end
Any idea?
[{ 1=>23 }, { 45=>87 }], as symbol names cannot begin with a digit?{ '1' => '23', '45' => '87' }(one hash without wrapped array) is a better result.