B
Bil Kleb
I've got a mental block on refactoring the following,
# given a hash of arrays,
hash = { 1=>[:a,:b,:c], 2=>[:d,:e], 3=>[:a,:c] }
# remove a specified element from the arrays if present
hash.each{ |k,v| hash[k] = v.delete_if{|e| e==:a} }
=> { 1=>[:b,:c], 2=>[:d,:e], 3=>[:c] }
Isn't there a simpler way to remove the matching
elements? (Maybe my data structure is just lame?)
Thanks,
# given a hash of arrays,
hash = { 1=>[:a,:b,:c], 2=>[:d,:e], 3=>[:a,:c] }
# remove a specified element from the arrays if present
hash.each{ |k,v| hash[k] = v.delete_if{|e| e==:a} }
=> { 1=>[:b,:c], 2=>[:d,:e], 3=>[:c] }
Isn't there a simpler way to remove the matching
elements? (Maybe my data structure is just lame?)
Thanks,