Method: Pathname#children
- Defined in:
- lib/pathname.rb
#children(with_directory = true) ⇒ Object
Returns the children of the directory (files and subdirectories, not recursive) as an array of Pathname objects.
By default, the returned pathnames will have enough information to access the files. If you set with_directory to false, then the returned pathnames will contain the filename only.
For example:
pn = Pathname("/usr/lib/ruby/1.8")
pn.children
# -> [ Pathname:/usr/lib/ruby/1.8/English.rb,
Pathname:/usr/lib/ruby/1.8/Env.rb,
Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ]
pn.children(false)
# -> [ Pathname:English.rb, Pathname:Env.rb, Pathname:abbrev.rb, ... ]
Note that the results never contain the entries . and .. in the directory because they are not children.
449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/pathname.rb', line 449 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 end |