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

ruby-changes:7943

From: mame <ko1@a...>
Date: Tue, 23 Sep 2008 09:04:00 +0900 (JST)
Subject: [ruby-changes:7943] Ruby:r19465 (trunk): * lib/pathname.rb (each_filename): return Enumerator if no block

mame	2008-09-23 09:03:42 +0900 (Tue, 23 Sep 2008)

  New Revision: 19465

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

  Log:
    * lib/pathname.rb (each_filename): return Enumerator if no block
      given.
    
    * test/pathname/test_pathname.rb: add a test for above.

  Modified files:
    trunk/ChangeLog
    trunk/lib/pathname.rb
    trunk/test/pathname/test_pathname.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19464)
+++ ChangeLog	(revision 19465)
@@ -1,3 +1,10 @@
+Tue Sep 23 09:01:15 2008  Yusuke Endoh  <mame@t...>
+
+	* lib/pathname.rb (each_filename): return Enumerator if no block
+	  given.
+
+	* test/pathname/test_pathname.rb: add a test for above.
+
 Tue Sep 23 08:25:56 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* hash.c (env_aset): allow nil value to remove an entry.
Index: lib/pathname.rb
===================================================================
--- lib/pathname.rb	(revision 19464)
+++ lib/pathname.rb	(revision 19465)
@@ -517,6 +517,7 @@
   #     # yields "usr", "bin", and "ruby".
   #
   def each_filename # :yield: filename
+    return to_enum(__method__) unless block_given?
     prefix, names = split_names(@path)
     names.each {|filename| yield filename }
     nil
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 19464)
+++ test/pathname/test_pathname.rb	(revision 19465)
@@ -481,6 +481,7 @@
     result = []
     Pathname.new("/usr/bin/ruby").each_filename {|f| result << f }
     assert_equal(%w[usr bin ruby], result)
+    assert_equal(%w[usr bin ruby], Pathname.new("/usr/bin/ruby").each_filename.to_a)
   end
 
   def test_kernel_pathname

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

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