Rails: Remove element from array of hashes
How about
array.delete_if {|key, value| value == "[email protected]" }
I think you're looking for this:
filtered_array = array.reject { |h| blacklist.include? h['email'] }
or if you want to use select
instead of reject
(perhaps you don't want to hurt anyone's feelings):
filtered_array = array.select { |h| !blacklist.include? h['email'] }
Your
array.select {|k,v| ...
attempt won't work because array hands the Enumerable blocks a single element and that element will be a Hash in this case, the |k,v|
trick would work if array
had two element arrays as elements though.