What if instead of removing duplicate elements from an array, I want to remove elements that have a specific property in common?
Specifically, I want to remove all strings from an array with duplicate "essences", where essence is defined like this:
class String
def essence
downcase.gsub('&', 'and').gsub(/[^a-z0-9]/, '')
end
end
I want something like this:
['a', 'A', 'b'].uniq_by(&:essence)
# => ['a', 'b'] (or ['A', 'b']; I don't really care)
What's the best way to accomplish this?