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

二次信任 提交于 2019-12-19 05:03:15

问题


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

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.


回答1:


Yes, it is possible using the fnmatch method:

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


来源:https://stackoverflow.com/questions/7186361/how-do-i-test-whether-a-string-would-match-a-glob-in-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!