Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

string

ruby

glob

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.

like image 576
Andrew Grimm Avatar asked Aug 25 '11 07:08

Andrew Grimm


1 Answers

Yes, it is possible using the fnmatch method:

File.fnmatch("foo*", "food") #=> true
like image 160
sepp2k Avatar answered Nov 06 '22 15:11

sepp2k