I'm trying to delete an attribute and its value from a hash. Its seems simple based on answers I see on here but it doesn't appear to work for me. Curious if anyone has any thoughts as to why? Also... this is NOT a duplicate of the question that was linked. I have tried except and slice... neither of those work as well. I'm guessing my dataset it different.
Here is an example hash I have:
{:data=>[{:id=>1, :make=>"Ford", :model=>"Excursion", :year=>2018, :color=>"silver", :vin=>"123456789F22"},{=>[{:id=>2, :make=>"Mazda", :model=>"RX7", :year=>1980, :color=>"blue", :vin=>"123456789F22"},{=>[{:id=>3, :make=>"Chevy", :model=>"Dorado", :year=>2018, :color=>"white", :vin=>"123456789F22"}]}
I have tried the following:
hashval.delete("color")
hashval.except!("color")
hashval.each {|h| h.delete("color")}
I also tried :color in case the string format was wrong
hashval.delete(:color)
hashval.except!(:color)
hashval.each {|h| h.delete(:color)}
but when I try to display the resulting hash
logger.info "hash result: #{hashval}"
I still see the original hash with the color still in there. Any thoughts on what I am doing wrong?
Ok... more info! If I do this:
hashval.delete(:data)
It does delete :data (and everything else after that). So it has something to do with the attributes in that hash array?
As it turns out, the answer is:
hashval = { data: vehicles.map { |v| v.table_data.except(:color) } }
I guess this issue was marked closed as a duplicate (even though it wasn't) so I cant add the solution.