summaryrefslogtreecommitdiff
path: root/lib/pathname.rb
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
commit2546a366ed0c20fb6ac644dfedd222ec471c0e46 (patch)
treed73aab8b3a9c5bbc1d1724c00d7199347f2a3bf7 /lib/pathname.rb
parent8b33b47ea0005ceadd817a42eee2222184dc74ea (diff)
* lib/pathname.rb (Pathname#initialize): fix pathname initialization
by pathname. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pathname.rb')
-rw-r--r--lib/pathname.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/pathname.rb b/lib/pathname.rb
index ac420a5cae..663afcf5ed 100644
--- a/lib/pathname.rb
+++ b/lib/pathname.rb
@@ -185,7 +185,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_str if path.respond_to? :to_str
+ @path = path.dup
if /\0/ =~ @path
raise ArgumentError, "pathname contains \\0: #{@path.inspect}"
@@ -882,6 +883,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