如何测试字符串是否与Ruby中的glob匹配?

时间:2022-09-01 23:43:04

Without hitting the filesystem, is it possible to see whether the glob "foo*" would match "food" in Ruby?

没有命中文件系统,是否有可能看到glob“foo *”是否匹配Ruby中的“food”?

Background: one of my scripts produce files, and I'd like to unit test that other scripts would be able to detect such files with their current glob.

背景:我的一个脚本生成文件,我想单元测试其他脚本能够用当前的glob检测这些文件。

1 个解决方案

#1


36  

Yes, it is possible using the fnmatch method:

是的,可以使用fnmatch方法:

File.fnmatch("foo*", "food") #=> true

#1


36  

Yes, it is possible using the fnmatch method:

是的,可以使用fnmatch方法:

File.fnmatch("foo*", "food") #=> true