31

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.

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338

1 Answers1

48

Yes, it is possible using the fnmatch method:

File.fnmatch("foo*", "food") #=> true
sepp2k
  • 363,768
  • 54
  • 674
  • 675