[前][次][番号順一覧][スレッド一覧]

ruby-changes:10368

From: akr <ko1@a...>
Date: Sat, 31 Jan 2009 14:23:58 +0900 (JST)
Subject: [ruby-changes:10368] Ruby:r21911 (trunk): * lib/pathname.rb (Pathname#each_child): new method.

akr	2009-01-31 14:13:49 +0900 (Sat, 31 Jan 2009)

  New Revision: 21911

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21911

  Log:
    * lib/pathname.rb (Pathname#each_child): new method.

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/pathname.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21910)
+++ ChangeLog	(revision 21911)
@@ -1,3 +1,7 @@
+Sat Jan 31 14:12:43 2009  Tanaka Akira  <akr@f...>
+
+	* lib/pathname.rb (Pathname#each_child): new method.
+
 Sat Jan 31 00:07:49 2009  Tanaka Akira  <akr@f...>
 
 	* lib/test/unit/assertions.rb
Index: lib/pathname.rb
===================================================================
--- lib/pathname.rb	(revision 21910)
+++ lib/pathname.rb	(revision 21911)
@@ -92,6 +92,7 @@
 # - #realpath
 # - #realdirpath
 # - #children
+# - #each_child
 # - #mountpoint?
 #
 # === File status predicate methods
@@ -716,7 +717,37 @@
     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
   # +self+ is relative, the argument must be relative too.
Index: NEWS
===================================================================
--- NEWS	(revision 21910)
+++ NEWS	(revision 21911)
@@ -86,7 +86,8 @@
     string/symbol.
 
 * pathname
-  * realdirpath
+  * new method: realdirpath
+  * new method: each_child
 
 === Compatibility issues (excluding feature bug fixes)
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]