I want to construct a hash, the problem is that I have some customers that are buyers and others that are sellers that can have the same name and I need to group them in a hash by name. Something like this:
customers = {"name1": {"buyers": [id11,..,id1n], "sellers": [ids1,..,ids1n]},
"name2": {"buyers": [id2,..,id], "sellers": [id1,..,idn] }}
The name is the key and the value is the hash with buyers and sellers, but I don't know how to initialize the hash and how to add a new key, value.
Suppose that I have the Customer.all and I can for example ask:
Customer.all do |customer|
if customer.buyer?
puts customer.name, customer.id
end
end