I thought this would be an interesting question to post. I have a solution, I'm curious if there is a better way to do this. Say you have this array:
names = ["on", "question", "quest"]
I want to eliminate strings that are substrings of other members in the array. The cleanest code I could come up with is:
names.select do |name|
names.all? { |other_name| other_name == name || other_name.match(name).nil? }
end
The result is
["question"]
I hate that code, just doesn't seem very ruby like. Any suggestions on a better / more efficient / more concise way to do this?
Thanks for the help.
other_name == name ||necessary? Would be a bit cleaner without it.