aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-27 12:41:10 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-27 12:41:10 +0000
commitd8cf22793bf09fd73b2a69703ed1c89ae7aa46af (patch)
tree470c0a21f4d0d960c2d66680aeeae8c39acc3ffe
parent94e5d6ba19ffd14e5c97fa2f428296def9f03ae5 (diff)
downloadruby-d8cf22793bf09fd73b2a69703ed1c89ae7aa46af.tar.gz
* lib/pathname.rb (Pathname#initialize): fix pathname initialization
by pathname. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/pathname.rb10
2 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 910b333cd9..40b4a1e0e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu May 27 21:37:50 2004 Tanaka Akira <akr@m17n.org>
+
+ * lib/pathname.rb (Pathname#initialize): fix pathname initialization
+ by pathname.
+
Thu May 27 20:02:09 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* io.c (rb_io_fwrite): check all case errno != 0 [ruby-dev:23648]
diff --git a/lib/pathname.rb b/lib/pathname.rb
index c4d0ea586a..bd8afb081d 100644
--- a/lib/pathname.rb
+++ b/lib/pathname.rb
@@ -187,7 +187,8 @@ class Pathname
# If +path+ contains a NUL character (<tt>\0</tt>), an ArgumentError is raised.
#
def initialize(path)
- @path = path.to_str.dup
+ path = path.to_path if path.respond_to? :to_path
+ @path = path.dup
if /\0/ =~ @path
raise ArgumentError, "pathname contains \\0: #{@path.inspect}"
@@ -890,6 +891,13 @@ if $0 == __FILE__
require 'test/unit'
class PathnameTest < Test::Unit::TestCase # :nodoc:
+ def test_initialize
+ p1 = Pathname.new('a')
+ assert_equal('a', p1.to_s)
+ p2 = Pathname.new(p1)
+ assert_equal(p1, p2)
+ end
+
class AnotherStringLike # :nodoc:
def initialize(s) @s = s end
def to_str() @s end