I have an array of hashed names and letters, for example:
array = [{"email"=>" test@test.com ", "name"=>"Test"}, {"email"=>" testA@gmail.com ", "name"=>"Test A"}, {"name"=>"Test B", "email"=>" testB@test.com "}, {"email"=>" testC@yahoo.com ", "name"=>"Test C"}, {"name"=>"Test D", "email"=>" testD@hotmail.com "}, {"email"=>" testE@test.com "}, {"name"=>"Test F", "email"=>" testF@test.com "}]
I want to filter out specific letters in a blacklist array. The following works, but it is too much.
blacklist = ["@test.com", "@gmail.com"] na = array blacklist.each do |b| na = na.reject{ |e| e["email"].include?(b) } end # na => [{"email"=>" testC@yahoo.com ", "name"=>"Test C"}, {"name"=>"Test D", "email"=>" testD@hotmail.com "}]
Can someone help me by putting this in a sexy ruby ββsingle line?
source share