From 8cc36df9c325327d5984b4139d97cce043b0898f Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 31 Jan 2009 05:13:49 +0000 Subject: * lib/pathname.rb (Pathname#each_child): new method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/pathname.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'lib') diff --git a/lib/pathname.rb b/lib/pathname.rb index 788e7d4e3f..c24687bffd 100644 --- a/lib/pathname.rb +++ b/lib/pathname.rb @@ -92,6 +92,7 @@ # - #realpath # - #realdirpath # - #children +# - #each_child # - #mountpoint? # # === File status predicate methods @@ -716,6 +717,36 @@ class Pathname result end + # Iterates over the children of the directory + # (files and subdirectories, not recursive). + # It yields Pathname object for each child. + # By default, the yielded 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. + # + # Pathname("/usr/local").each_child {|f| p f } + # #=> # + # # # + # # # + # # # + # # # + # # # + # # # + # # # + # + # Pathname("/usr/local").each_child(false) {|f| p f } + # #=> # + # # # + # # # + # # # + # # # + # # # + # # # + # # # + # + def each_child(with_directory=true, &b) + children(with_directory).each(&b) + end + # # #relative_path_from returns a relative path from the argument to the # receiver. If +self+ is absolute, the argument must be absolute too. If -- cgit v1.2.3