【发布时间】:2016-02-03 13:12:21
【问题描述】:
我正在遍历一些文件,并且需要跳过路径中有特定子字符串的文件。这些子字符串被定义为一个数组。例如:
Dir.glob("#{temp_dir}/**/*").each do |file|
# Skip files in the ignore list
if (file.downcase.index("__macosx"))
next
end
puts file
end
上面的代码成功地跳过了带有__macosx 的任何文件路径,但我需要对其进行调整以使用子字符串数组,如下所示:
if (file.downcase.index(["__macosx", ".ds_store"]))
next
end
我怎样才能做到这一点,同时避免编写额外的循环来迭代子字符串数组?
【问题讨论】: