File.basename, dirname and split changed in 1.8.0!

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default 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?

    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
    Thomas Guest

  2. Similar Questions and Discussions

    1. Can I split a pdf file?
      Is it possible to split the pdf by using applescript to a set number of repeating pages say every 200 pages
    2. #38933 [NEW]: dirname not support binary file path
      From: foxgoblin at gmail dot com Operating system: Windows XP PHP version: 5.1.6 PHP Bug Type: Directory function related...
    3. strange behavior in File::Basename
      I'm using Perl 5.6.1 on Debian Linux 3.0 I noticed the module File::Basename doesn't behave like the shell commands basename/dirname in a special...
    4. File::Basename
      From how I understood it file::basename was able to tell figure out the filename without path for both windows and UNIX. I have an html page that...
    5. Dirname File
      Hi. I have a problem with a dirname. I canīt read a file if i write this code: <?php $user = $_REQUEST; $filename =...
  3. #2

    Default Re: File.basename, dirname and split changed in 1.8.0!

    Yukihiro Matsumoto wrote:
    > Hi,
    >
    > In message "File.basename, dirname and split changed in 1.8.0!"
    > on 03/08/14, Thomas <thomass@deltadata.dk> writes:
    >
    > |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?


    Joel VanderWerf Guest

  4. #3

    Default Re: File.basename, dirname and split changed in 1.8.0!

    Hi,

    In message "Re: File.basename, dirname and split changed in 1.8.0!"
    on 03/08/14, Joel VanderWerf <vjoel@PATH.Berkeley.EDU> writes:

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

    I think so.

    matz.

    Yukihiro Matsumoto Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139