summaryrefslogtreecommitdiff
path: root/ext/pathname/lib/pathname.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-14 15:14:46 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-14 15:14:46 +0000
commit8bb581f8dd4eeb0e3e784488f3c8d102df9327c3 (patch)
treebce0e4da41f5fe3d2e3b6547a4a0ec5cfb0eaca0 /ext/pathname/lib/pathname.rb
parent16917fa6980cd90678e5149fa37151038094205a (diff)
* ext/pathname/lib/pathname.rb (descend): Blockless form supported.
(ascend): Ditto. [ruby-core:68820] [Feature #11052] Patch by Piotr Szotkowski. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/pathname/lib/pathname.rb')
-rw-r--r--ext/pathname/lib/pathname.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb
index f5db526b8c..9f23ba502e 100644
--- a/ext/pathname/lib/pathname.rb
+++ b/ext/pathname/lib/pathname.rb
@@ -278,9 +278,17 @@ class Pathname
# #<Pathname:path/to/some>
# #<Pathname:path/to/some/file.rb>
#
+ # Returns an Enumerator if no block was given.
+ #
+ # enum = Pathname.new("/usr/bin/ruby").descend
+ # # ... do stuff ...
+ # enum.each { |e| ... }
+ # # yields Pathnames /, /usr, /usr/bin, and /usr/bin/ruby.
+ #
# It doesn't access the filesystem.
#
def descend
+ return to_enum(__method__) unless block_given?
vs = []
ascend {|v| vs << v }
vs.reverse_each {|v| yield v }
@@ -303,9 +311,17 @@ class Pathname
# #<Pathname:path/to>
# #<Pathname:path>
#
+ # Returns an Enumerator if no block was given.
+ #
+ # enum = Pathname.new("/usr/bin/ruby").ascend
+ # # ... do stuff ...
+ # enum.each { |e| ... }
+ # # yields Pathnames /usr/bin/ruby, /usr/bin, /usr, and /.
+ #
# It doesn't access the filesystem.
#
def ascend
+ return to_enum(__method__) unless block_given?
path = @path
yield self
while r = chop_basename(path)