Sha256: 01493a45d120435c270c96dcc17b662328ee5cd43022935f00c14b91d8cdd458

Contents?: true

Size: 966 Bytes

Versions: 16

Compression:

Stored size: 966 Bytes

Contents

class Dir

  # Ascend a directory path.

  def self.ascend( dir, inclusive=true, &blk)
    dir = dir.dup
    blk.call( dir ) if inclusive
    ri = dir.rindex('/')
    while ri
      dir = dir.slice(0...ri)
      if dir == ""
        blk.call( '/' ) ; break
      end
      blk.call( dir )
      ri = dir.rindex('/')
    end
  end

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCDir < Test::Unit::TestCase

    def test_ascend_1
      c = []
      Dir.ascend( "this/path/up" ) do |path|
        c << path
      end
      assert_equal( 'this/path/up', c[0] )
      assert_equal( 'this/path', c[1] )
      assert_equal( 'this', c[2] )
    end

    def test_ascend_2
      c = []
      Dir.ascend( "this/path/up", false ) do |path|
        c << path
      end
      assert_equal( 'this/path', c[0] )
      assert_equal( 'this', c[1] )
    end

  end

=end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
facets-1.4.0 lib/facets/core/dir/self/ascend.rb
facets-1.4.1 lib/facets/core/dir/self/ascend.rb
facets-1.4.2 lib/facets/core/dir/self/ascend.rb
facets-1.4.3 lib/facets/core/dir/self/ascend.rb
facets-1.4.5 lib/facets/core/dir/self/ascend.rb
facets-1.4.4 lib/facets/core/dir/self/ascend.rb
facets-1.7.30 lib/facets/core/dir/self/ascend.rb
facets-1.7.0 lib/facets/core/dir/self/ascend.rb
facets-1.7.38 lib/facets/core/dir/self/ascend.rb
facets-1.7.46 lib/facets/core/dir/self/ascend.rb
facets-1.8.0 lib/facets/core/dir/self/ascend.rb
facets-1.8.20 lib/facets/core/dir/self/ascend.rb
facets-1.8.51 lib/facets/core/dir/self/ascend.rb
facets-1.8.49 lib/facets/core/dir/self/ascend.rb
facets-1.8.54 lib/facets/core/dir/self/ascend.rb
facets-1.8.8 lib/facets/core/dir/self/ascend.rb