如何改进这种排序方法以满足以下条件:
- 首先返回完全匹配
- 部分匹配遵循完全匹配
def find_me
records = ["gogol", "garrison", "feathers", "grains"]
sorted = []
print "what are you looking for? "
term = gets.chomp.downcase
records.select do |record|
if term == record.downcase
#exact match
sorted << record
elsif term[0] == record[0] or term[1] == record[1] or term[2] == record[2]
#if the first three chars match add it
sorted << record
end
end
sorted.sort! {|b| term <=> b }
end