Feature #7360 ยป 19c4ae36aaea65b30e8b73c89f7ac42bd6905ed7.patch
ext/pathname/lib/pathname.rb | ||
---|---|---|
Pathname.new(File.join(*relpath_names))
|
||
end
|
||
end
|
||
#
|
||
# Returns or yields Pathname objects that match the given glob
|
||
# pattern or glob patterns, relative to +self+.
|
||
#
|
||
# It joins +self+ with the given glob pattern. +self+ should be a
|
||
# directory. When +pattern+ is an absolute path, +self+ does not
|
||
# matter.
|
||
#
|
||
# Pathname('config').glob("*.rb")
|
||
# #=> [#<Pathname:config/environment.rb>, #<Pathname:config/routes.rb>, ..]
|
||
#
|
||
# Pathname('config').glob(["*.rb", "*.txt"])
|
||
# #=> [#<Pathname:config/environment.rb>, #<Pathname:config/routes.rb>, ..]
|
||
#
|
||
# See Dir.glob.
|
||
#
|
||
def glob(pattern, flags = 0, &b)
|
||
Array(pattern).flat_map do |pat|
|
||
self.class.glob(join(pat), flags, &b)
|
||
end
|
||
end
|
||
end
|
||
test/pathname/test_pathname.rb | ||
---|---|---|
}
|
||
end
|
||
def test_glob
|
||
with_tmpchdir('rubytest-pathname') {|dir|
|
||
open("f", "w") {|f| f.write "abc" }
|
||
Dir.mkdir("d")
|
||
assert_equal([Pathname("d"), Pathname("f")], Pathname('').glob("*").sort)
|
||
a = []
|
||
Pathname('').glob("*") {|path| a << path }
|
||
a.sort!
|
||
assert_equal([Pathname("d"), Pathname("f")], a)
|
||
open("FOO.txt", "w") {|f| f.write "abc" }
|
||
assert_equal([Pathname("FOO.txt")], Pathname('').glob("foo.*", File::FNM_CASEFOLD))
|
||
}
|
||
with_tmpchdir('rubytest-pathname') {|dir|
|
||
open("a.rb", "w") {|f| f.write "abc" }
|
||
open("a.txt", "w") {|f| f.write "abc" }
|
||
assert_equal([Pathname("a.rb"), Pathname("a.txt")], Pathname('').glob(["*.rb", "*.txt"]))
|
||
}
|
||
end
|
||
def test_s_getwd
|
||
wd = Pathname.getwd
|
||
assert_kind_of(Pathname, wd)
|