How do I test whether a string would match a glob in Ruby?
问题 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