I have an array of hashes as below
status_arr = [{id: 5, status: false},
{id: 7, status: false},
{id: 3, status: false},
{id: 9, status: false} ]
I would like to update the hash with status: true if it has ids 5, 7
update_ids = [5, 9]
I am trying the following and has no idea to proceed
status_arr.select{ |arr| update_ids.include?(arr[:id]) arr[:status] = true}
Expected output:
status_arr = [{id: 5, status: true},
{id: 7, status: false},
{id: 3, status: false},
{id: 9, status: true} ]
status_arr.select{ |arr| update_ids.include?(arr[:id]) arr[:status] = true}tostatus_arr.select{ |arr| update_ids.include?(arr[:id])}.each{|arr| arr[:status] = true}orstatus_arr.each{ |arr| arr[:status] = update_ids.include?(arr[:id]) }status_arr.select{ |arr| arr[:status] = true if update_ids.include?(arr[:id])}status_arr.map { |h| h.merge(status: [5,9].include?(h[:id])) }