Method: Pa::Directory::ClassMethods#glob2

Defined in:
lib/pa/directory.rb

#glob2(*paths, o = {}) ⇒ Array<String> #glob2(*paths, o = {}) {|path| ... } ⇒ nil

Note:

glob is * ** ? [set] a,b

path globbing, exclude ‘.’ ‘..’

Overloads:

  • #glob2(*paths, o = {}) ⇒ Array<String>

    Parameters:

    • (defaults to: {})

      option

    Options Hash (o):

    • :dotmatch (Boolean) — default: false

      match dot file. FNM_DOTMATCH

    • :pathname (Boolean) — default: false

      wildcard doesn’t match /. FNM_PATHNAME

    • :noescape (Boolean) — default: false

      makes ‘\’ ordinary. FNM_NOESCAPE

    Returns:

  • #glob2(*paths, o = {}) {|path| ... } ⇒ nil

    Yield Parameters:

    • path (String)

    Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pa/directory.rb', line 40

def glob2(*args, &blk)
  paths, o = Util.extract_options(args)
  paths.map!{|v|get(v)}
  blk ||= proc { |path| path }

  flag = 0
  o.each do |option, value|
    flag |= File.const_get("FNM_#{option.upcase}") if value
  end

  # delete . .. 
  files = Dir.glob(paths, flag).delete_if{|v| v =~ %r~(^|/)\.\.?$~}

  ret = []
  files.each { |path|
    ret << blk.call(path)
  }

  ret
end