开发者

How do I test whether a string would match a glob in Ruby?

开发者 https://www.devze.com 2023-03-30 08:34 出处:网络
Without hitting the filesystem, is it possible to see whether the glob \"foo*\" would match \"food\" in Ruby?

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

Background: one of my s开发者_开发知识库cripts produce files, and I'd like to unit test that other scripts would be able to detect such files with their current glob.


Yes, it is possible using the fnmatch method:

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

精彩评论

暂无评论...
验证码 换一张
取 消