mirror of
https://github.com/ruby/ruby.git
synced 2026-08-01 02:20:48 +08:00
pathname: Use Dir.children
This commit is contained in:
parent
997e11cf37
commit
407398b079
Notes:
git
2026-05-13 08:39:01 +00:00
@ -766,15 +766,12 @@ class Pathname
|
||||
#
|
||||
def children(with_directory=true)
|
||||
with_directory = false if @path == '.'
|
||||
result = []
|
||||
Dir.foreach(@path) {|e|
|
||||
next if e == '.' || e == '..'
|
||||
if with_directory
|
||||
result << self.class.new(File.join(@path, e))
|
||||
else
|
||||
result << self.class.new(e)
|
||||
end
|
||||
}
|
||||
result = Dir.children(@path)
|
||||
if with_directory
|
||||
result.map! {|e| self.class.new(File.join(@path, e))}
|
||||
else
|
||||
result.map! {|e| self.class.new(e)}
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user