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

前端 未结 1 1429
逝去的感伤
逝去的感伤 2020-12-11 00:29

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

Background:

相关标签:
1条回答
  • 2020-12-11 00:32

    Yes, it is possible using the fnmatch method:

    File.fnmatch("foo*", "food") #=> true
    
    0 讨论(0)
提交回复
热议问题