* lib/pathname.rb: version information is added in document.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
92abdcefe4
commit
4fca6e91dc
@ -1,3 +1,7 @@
|
|||||||
|
Sun Oct 5 23:27:09 2003 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* lib/pathname.rb: version information is added in document.
|
||||||
|
|
||||||
Sun Oct 5 23:07:03 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun Oct 5 23:07:03 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (rb_f_END): block should be given. [ruby-dev:21497]
|
* eval.c (rb_f_END): block should be given. [ruby-dev:21497]
|
||||||
|
@ -6,12 +6,15 @@
|
|||||||
#
|
#
|
||||||
# Pathname is immutable. It has no method for destructive update.
|
# Pathname is immutable. It has no method for destructive update.
|
||||||
#
|
#
|
||||||
|
# pathname.rb is distributed with Ruby since 1.8.0.
|
||||||
class Pathname
|
class Pathname
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@path = path.to_str.dup
|
@path = path.to_str.dup
|
||||||
@path.freeze
|
@path.freeze
|
||||||
|
|
||||||
raise ArgumentError, "pathname contains \\0: #{@path.inspect}" if /\0/ =~ @path
|
if /\0/ =~ @path
|
||||||
|
raise ArgumentError, "pathname contains \\0: #{@path.inspect}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
@ -33,6 +36,8 @@ class Pathname
|
|||||||
def to_s
|
def to_s
|
||||||
@path.dup
|
@path.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# to_str is implemented for Pathname object usable with File.open, etc.
|
||||||
alias to_str to_s
|
alias to_str to_s
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
@ -226,6 +231,8 @@ class Pathname
|
|||||||
# Pathname#children returns the children of the directory as an array of
|
# Pathname#children returns the children of the directory as an array of
|
||||||
# pathnames. I.e. it is similar to Pathname#entries except '.' and '..'
|
# pathnames. I.e. it is similar to Pathname#entries except '.' and '..'
|
||||||
# is not returned.
|
# is not returned.
|
||||||
|
#
|
||||||
|
# This method is exist since 1.8.1.
|
||||||
def children
|
def children
|
||||||
Dir.entries(@path).map {|f|
|
Dir.entries(@path).map {|f|
|
||||||
f == '.' || f == '..' ? nil : Pathname.new(f)
|
f == '.' || f == '..' ? nil : Pathname.new(f)
|
||||||
@ -242,9 +249,11 @@ class Pathname
|
|||||||
#
|
#
|
||||||
# ArgumentError is raised when it cannot find a relative path.
|
# ArgumentError is raised when it cannot find a relative path.
|
||||||
#
|
#
|
||||||
|
# This method is exist since 1.8.1.
|
||||||
def relative_path_from(base_directory)
|
def relative_path_from(base_directory)
|
||||||
if self.absolute? != base_directory.absolute?
|
if self.absolute? != base_directory.absolute?
|
||||||
raise ArgumentError, "relative path between absolute and relative path: #{self.inspect}, #{base_directory.inspect}"
|
raise ArgumentError,
|
||||||
|
"relative path between absolute and relative path: #{self.inspect}, #{base_directory.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
dest = []
|
dest = []
|
||||||
@ -281,7 +290,14 @@ end
|
|||||||
|
|
||||||
# IO
|
# IO
|
||||||
class Pathname
|
class Pathname
|
||||||
|
# Pathname#each_line iterates over lines of the file.
|
||||||
|
# It's yields String objects for each line.
|
||||||
|
#
|
||||||
|
# This method is exist since 1.8.1.
|
||||||
def each_line(*args, &block) IO.foreach(@path, *args, &block) end
|
def each_line(*args, &block) IO.foreach(@path, *args, &block) end
|
||||||
|
|
||||||
|
# This method is obsoleted at 1.8.1.
|
||||||
|
#
|
||||||
alias foreachline each_line # compatibility to 1.8.0. obsoleted.
|
alias foreachline each_line # compatibility to 1.8.0. obsoleted.
|
||||||
|
|
||||||
def read(*args) IO.read(@path, *args) end
|
def read(*args) IO.read(@path, *args) end
|
||||||
@ -357,6 +373,8 @@ class Pathname
|
|||||||
def Pathname.getwd() Pathname.new(Dir.getwd) end
|
def Pathname.getwd() Pathname.new(Dir.getwd) end
|
||||||
class << self; alias pwd getwd end
|
class << self; alias pwd getwd end
|
||||||
|
|
||||||
|
# This method is obsoleted at 1.8.1.
|
||||||
|
#
|
||||||
def chdir(&block) # compatibility to 1.8.0.
|
def chdir(&block) # compatibility to 1.8.0.
|
||||||
warn "Pathname#chdir is obsoleted. Use Dir.chdir."
|
warn "Pathname#chdir is obsoleted. Use Dir.chdir."
|
||||||
Dir.chdir(@path, &block)
|
Dir.chdir(@path, &block)
|
||||||
@ -366,7 +384,14 @@ class Pathname
|
|||||||
def rmdir() Dir.rmdir(@path) end
|
def rmdir() Dir.rmdir(@path) end
|
||||||
def entries() Dir.entries(@path).map {|f| Pathname.new(f) } end
|
def entries() Dir.entries(@path).map {|f| Pathname.new(f) } end
|
||||||
|
|
||||||
|
# Pathname#each_entry iterates over entries of the directory.
|
||||||
|
# It's yields Pathname objects for each entry.
|
||||||
|
#
|
||||||
|
# This method is exist since 1.8.1.
|
||||||
def each_entry(&block) Dir.foreach(@path) {|f| yield Pathname.new(f) } end
|
def each_entry(&block) Dir.foreach(@path) {|f| yield Pathname.new(f) } end
|
||||||
|
|
||||||
|
# This method is obsoleted at 1.8.1.
|
||||||
|
#
|
||||||
alias dir_foreach each_entry # compatibility to 1.8.0. obsoleted.
|
alias dir_foreach each_entry # compatibility to 1.8.0. obsoleted.
|
||||||
|
|
||||||
def mkdir(*args) Dir.mkdir(@path, *args) end
|
def mkdir(*args) Dir.mkdir(@path, *args) end
|
||||||
@ -409,6 +434,8 @@ class Pathname
|
|||||||
end
|
end
|
||||||
alias delete unlink
|
alias delete unlink
|
||||||
|
|
||||||
|
# This method is obsoleted at 1.8.1.
|
||||||
|
#
|
||||||
def foreach(*args, &block) # compatibility to 1.8.0. obsoleted.
|
def foreach(*args, &block) # compatibility to 1.8.0. obsoleted.
|
||||||
warn "Pathname#foreach is obsoleted. Use each_line or each_entry."
|
warn "Pathname#foreach is obsoleted. Use each_line or each_entry."
|
||||||
if FileTest.directory? @path
|
if FileTest.directory? @path
|
||||||
@ -535,7 +562,8 @@ if $0 == __FILE__
|
|||||||
assert_equal('a/..', Pathname.new('a/../.').cleanpath(true).to_s)
|
assert_equal('a/..', Pathname.new('a/../.').cleanpath(true).to_s)
|
||||||
|
|
||||||
assert_equal('/a', Pathname.new('/../.././../a').cleanpath(true).to_s)
|
assert_equal('/a', Pathname.new('/../.././../a').cleanpath(true).to_s)
|
||||||
assert_equal('a/b/../../../../c/../d', Pathname.new('a/b/../../../../c/../d').cleanpath(true).to_s)
|
assert_equal('a/b/../../../../c/../d',
|
||||||
|
Pathname.new('a/b/../../../../c/../d').cleanpath(true).to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cleanpath_no_symlink
|
def test_cleanpath_no_symlink
|
||||||
@ -600,7 +628,13 @@ if $0 == __FILE__
|
|||||||
|
|
||||||
def test_relative_path_from
|
def test_relative_path_from
|
||||||
assert_relpath("../a", "a", "b")
|
assert_relpath("../a", "a", "b")
|
||||||
|
assert_relpath("../a", "a", "b/")
|
||||||
|
assert_relpath("../a", "a/", "b")
|
||||||
|
assert_relpath("../a", "a/", "b/")
|
||||||
assert_relpath("../a", "/a", "/b")
|
assert_relpath("../a", "/a", "/b")
|
||||||
|
assert_relpath("../a", "/a", "/b/")
|
||||||
|
assert_relpath("../a", "/a/", "/b")
|
||||||
|
assert_relpath("../a", "/a/", "/b/")
|
||||||
|
|
||||||
assert_relpath("../b", "a/b", "a/c")
|
assert_relpath("../b", "a/b", "a/c")
|
||||||
assert_relpath("../a", "../a", "../b")
|
assert_relpath("../a", "../a", "../b")
|
||||||
@ -620,6 +654,8 @@ if $0 == __FILE__
|
|||||||
assert_relpath("../a", "/../a", "/b")
|
assert_relpath("../a", "/../a", "/b")
|
||||||
assert_relpath("../../a", "../a", "b")
|
assert_relpath("../../a", "../a", "b")
|
||||||
assert_relpath(".", "/a/../../b", "/b")
|
assert_relpath(".", "/a/../../b", "/b")
|
||||||
|
assert_relpath("..", "a/..", "a")
|
||||||
|
assert_relpath(".", "a/../b", "b")
|
||||||
|
|
||||||
assert_relpath("a", "a", "b/..")
|
assert_relpath("a", "a", "b/..")
|
||||||
assert_relpath("b/c", "b/c", "b/..")
|
assert_relpath("b/c", "b/c", "b/..")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user