我有一个从数据库中提取的标题列表,按字母顺序排序,即:
[
'Morning Glory',
'Red',
'Skyline',
'The Next Three Days'
]
重新排序忽略“The”的标题列表的最佳方法是什么,以便它变成:
[
'Morning Glory',
'The Next Three Days',
'Red',
'Skyline'
]
最佳答案
titles = ["Morning Glory", "Red", "Skyline", "The Next Three Days"]
titles.sort_by {|w| w.sub(/^the /i,"")}
=> ["Morning Glory", "The Next Three Days", "Red", "Skyline"]
关于ruby-on-rails - 如何使用 Ruby 按字母顺序排序标题列表,忽略 "The"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4251742/