summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--lib/pathname.rb1
-rw-r--r--test/pathname/test_pathname.rb1
3 files changed, 9 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 38f538d52d..b6f00ccfe6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Sep 23 09:01:15 2008 Yusuke Endoh <mame@tsg.ne.jp>
+
+ * 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@ruby-lang.org>
* hash.c (env_aset): allow nil value to remove an entry.
diff --git a/lib/pathname.rb b/lib/pathname.rb
index 45974545a6..1bc0063bb0 100644
--- a/lib/pathname.rb
+++ b/lib/pathname.rb
@@ -517,6 +517,7 @@ class Pathname
# # 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
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 11c1bb7b2b..da12383bdd 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -481,6 +481,7 @@ class TestPathname < Test::Unit::TestCase
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