如何使用Ruby按字母顺序排序标题列表,忽略"The"?

fch*_*sen 1 ruby ruby-on-rails

我有一个标题列表,我从数据库中按字母顺序排序,即:

[
  'Morning Glory',
  'Red',
  'Skyline',
  'The Next Three Days'
]
Run Code Online (Sandbox Code Playgroud)

什么是重新排序这个标题列表忽略"The"的最佳方式,以便它将成为:

[
  'Morning Glory',
  'The Next Three Days',
  'Red',
  'Skyline'
]
Run Code Online (Sandbox Code Playgroud)

gle*_*ald 8

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"]
Run Code Online (Sandbox Code Playgroud)