File.basename, dirname and split changed in 1.8.0!

T

Thomas

Why did the behaviour of File.basename, File.dirname and File.split
change in ruby 1.8.0?

The tests below run on 1.6.8( and 1.7.x, I think), but not on 1.8.0.

Is this intentional and what the rationale?

Cheers,

Thomas


require 'test/unit'

class BaseFileTest < Test::Unit::TestCase
def test_dirname
assert_equal("a/b/c", File.dirname("a/b/c/d"))
assert_equal(".", File.dirname("c"))
assert_equal("a/b", File.dirname("a/b/"))
end

def test_basename
assert_equal("d", File.basename("a/b/c/d"))
assert_equal("c", File.basename("c"))
assert_equal("", File.basename("a/b/"))
end

def test_split
assert_equal(["a/b/c", "d"], File.split("a/b/c/d"))
assert_equal(["a/b/c/d", ""], File.split("a/b/c/d/"))
assert_equal([".", "a"], File.split("a"))
end
end
 
J

Joel VanderWerf

Yukihiro said:
Hi,

In message "File.basename, dirname and split changed in 1.8.0!"

|Why did the behaviour of File.basename, File.dirname and File.split
|change in ruby 1.8.0?

To conform POSIX basename and dirname. Blame POSIX.

To summarize the examples, a trailing "/" is ignored. Is that the only
difference?
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: File.basename, dirname and split changed in 1.8.0!"

|To summarize the examples, a trailing "/" is ignored. Is that the only
|difference?

I think so.

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top