summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-31 05:13:49 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-31 05:13:49 +0000
commit8cc36df9c325327d5984b4139d97cce043b0898f (patch)
tree9d5bc4528a526bc9eb9de1b20e094ccd787d3e08
parent4a3e62b3836a239089f87e0aed7058856026b793 (diff)
* 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
-rw-r--r--ChangeLog4
-rw-r--r--NEWS3
-rw-r--r--lib/pathname.rb31
3 files changed, 37 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index b4160e77c7..a5f7f0aa2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Jan 31 14:12:43 2009 Tanaka Akira <akr@fsij.org>
+
+ * lib/pathname.rb (Pathname#each_child): new method.
+
Sat Jan 31 00:07:49 2009 Tanaka Akira <akr@fsij.org>
* lib/test/unit/assertions.rb
diff --git a/NEWS b/NEWS
index a54df1b2a6..89b975baa1 100644
--- a/NEWS
+++ b/NEWS
@@ -86,7 +86,8 @@ with all sufficient information, see the ChangeLog file.
string/symbol.
* pathname
- * realdirpath
+ * new method: realdirpath
+ * new method: each_child
=== Compatibility issues (excluding feature bug fixes)
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/share>
+ # # #<Pathname:/usr/local/bin>
+ # # #<Pathname:/usr/local/games>
+ # # #<Pathname:/usr/local/lib>
+ # # #<Pathname:/usr/local/include>
+ # # #<Pathname:/usr/local/sbin>
+ # # #<Pathname:/usr/local/src>
+ # # #<Pathname:/usr/local/man>
+ #
+ # Pathname("/usr/local").each_child(false) {|f| p f }
+ # #=> #<Pathname:share>
+ # # #<Pathname:bin>
+ # # #<Pathname:games>
+ # # #<Pathname:lib>
+ # # #<Pathname:include>
+ # # #<Pathname:sbin>
+ # # #<Pathname:src>
+ # # #<Pathname:man>
+ #
+ 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