1

我很惊讶我找不到这个问题的答案,但我需要选择在 Time.now 和 1.day.ago 之间修改的所有文件。显然,在处理 ruby​​ File 或 FileUtil 类时,我并不期望使用“ago”运算符,但如果有人向我展示了一个,我不会感到惊讶。:)

另一种方式是我认为的数组函数......也许涉及我从未使用过的'<=>'运算符

4

1 回答 1

3

也许是这样的?(未经测试):

selected_files = Dir.glob("*.pdf").select do |file|
  mtime = File.mtime(file)

  # if in a rails environment:
  # (1.day.ago .. Time.now).cover?(mtime)

  # if not in rails environment but want to use that code do this before that line:
  # require 'active_support/all'

  # else do the math:
  # mtime > (Time.now - 86400) and mtime < Time.now
end
于 2013-03-27T00:31:52.823 回答