mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
16917fa698
commit
8bb581f8dd
4 changed files with 36 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Mon Jun 15 00:14:33 2015 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/pathname/lib/pathname.rb (descend): Blockless form supported.
|
||||||
|
(ascend): Ditto.
|
||||||
|
[ruby-core:68820] [Feature #11052] Patch by Piotr Szotkowski.
|
||||||
|
|
||||||
Sun Jun 14 20:09:25 2015 Tanaka Akira <akr@fsij.org>
|
Sun Jun 14 20:09:25 2015 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* time.c (time_getlocaltime): [DOC] Add examples of valid utc_offset
|
* time.c (time_getlocaltime): [DOC] Add examples of valid utc_offset
|
||||||
|
|
4
NEWS
4
NEWS
|
@ -78,6 +78,10 @@ with all sufficient information, see the ChangeLog file.
|
||||||
* OpenSSL::SSL::SSLSocket#accept_nonblock and
|
* OpenSSL::SSL::SSLSocket#accept_nonblock and
|
||||||
OpenSSL::SSL::SSLSocket#connect_nonblock supports `exception: false`.
|
OpenSSL::SSL::SSLSocket#connect_nonblock supports `exception: false`.
|
||||||
|
|
||||||
|
* Pathname
|
||||||
|
* Pathname#descend and Pathname#ascend supported blockless form.
|
||||||
|
[Feature #11052]
|
||||||
|
|
||||||
* io/wait
|
* io/wait
|
||||||
* IO#wait_readable no longer checks FIONREAD, it may be used for
|
* IO#wait_readable no longer checks FIONREAD, it may be used for
|
||||||
non-bytestream IO such as listen sockets.
|
non-bytestream IO such as listen sockets.
|
||||||
|
|
|
@ -278,9 +278,17 @@ class Pathname
|
||||||
# #<Pathname:path/to/some>
|
# #<Pathname:path/to/some>
|
||||||
# #<Pathname:path/to/some/file.rb>
|
# #<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.
|
# It doesn't access the filesystem.
|
||||||
#
|
#
|
||||||
def descend
|
def descend
|
||||||
|
return to_enum(__method__) unless block_given?
|
||||||
vs = []
|
vs = []
|
||||||
ascend {|v| vs << v }
|
ascend {|v| vs << v }
|
||||||
vs.reverse_each {|v| yield v }
|
vs.reverse_each {|v| yield v }
|
||||||
|
@ -303,9 +311,17 @@ class Pathname
|
||||||
# #<Pathname:path/to>
|
# #<Pathname:path/to>
|
||||||
# #<Pathname:path>
|
# #<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.
|
# It doesn't access the filesystem.
|
||||||
#
|
#
|
||||||
def ascend
|
def ascend
|
||||||
|
return to_enum(__method__) unless block_given?
|
||||||
path = @path
|
path = @path
|
||||||
yield self
|
yield self
|
||||||
while r = chop_basename(path)
|
while r = chop_basename(path)
|
||||||
|
|
|
@ -430,7 +430,7 @@ class TestPathname < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def descend(path)
|
def descend(path)
|
||||||
Pathname.new(path).enum_for(:descend).map {|v| v.to_s }
|
Pathname.new(path).descend.map(&:to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
defassert(:descend, %w[/ /a /a/b /a/b/c], "/a/b/c")
|
defassert(:descend, %w[/ /a /a/b /a/b/c], "/a/b/c")
|
||||||
|
@ -439,7 +439,7 @@ class TestPathname < Test::Unit::TestCase
|
||||||
defassert(:descend, %w[a/], "a/")
|
defassert(:descend, %w[a/], "a/")
|
||||||
|
|
||||||
def ascend(path)
|
def ascend(path)
|
||||||
Pathname.new(path).enum_for(:ascend).map {|v| v.to_s }
|
Pathname.new(path).ascend.map(&:to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
defassert(:ascend, %w[/a/b/c /a/b /a /], "/a/b/c")
|
defassert(:ascend, %w[/a/b/c /a/b /a /], "/a/b/c")
|
||||||
|
@ -447,6 +447,14 @@ class TestPathname < Test::Unit::TestCase
|
||||||
defassert(:ascend, %w[./a/b/c ./a/b ./a .], "./a/b/c")
|
defassert(:ascend, %w[./a/b/c ./a/b ./a .], "./a/b/c")
|
||||||
defassert(:ascend, %w[a/], "a/")
|
defassert(:ascend, %w[a/], "a/")
|
||||||
|
|
||||||
|
def test_blockless_ascend_is_enumerator
|
||||||
|
assert_kind_of(Enumerator, Pathname.new('a').ascend)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_blockless_descend_is_enumerator
|
||||||
|
assert_kind_of(Enumerator, Pathname.new('a').descend)
|
||||||
|
end
|
||||||
|
|
||||||
def test_initialize
|
def test_initialize
|
||||||
p1 = Pathname.new('a')
|
p1 = Pathname.new('a')
|
||||||
assert_equal('a', p1.to_s)
|
assert_equal('a', p1.to_s)
|
||||||
|
|
Loading…
Reference in a new issue