Sha256: 77f09540beb66f62567f14561d33d5af02bbd53928c1298c1500d9174086704a

Contents?: true

Size: 940 Bytes

Versions: 10

Compression:

Stored size: 940 Bytes

Contents

class Dir

  #
  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

10 entries across 10 versions & 1 rubygems

Version Path
facets-1.0.0 lib/facet/dir/self/ascend.rb
facets-1.0.3 packages/core/lib/facet/dir/self/ascend.rb
facets-0.9.0 lib/nano/dir/self/ascend.rb
facets-1.3.0 lib/facets/core/dir/self/ascend.rb
facets-1.2.1 lib/facets/core/dir/self/ascend.rb
facets-1.2.0 lib/facets/core/dir/self/ascend.rb
facets-1.1.0 lib/facet/dir/self/ascend.rb
facets-1.3.1 lib/facets/core/dir/self/ascend.rb
facets-1.3.2 lib/facets/core/dir/self/ascend.rb
facets-1.3.3 lib/facets/core/dir/self/ascend.rb