Sha256: 49ea66e2f7ec4fd4f65728809be767026ed077a80b58ed92c482466754cae900

Contents?: true

Size: 525 Bytes

Versions: 7

Compression:

Stored size: 525 Bytes

Contents

class File

  # Returns only the first portion of the directory of
  # a file path name.
  #
  #   File.rootname('lib/jump.rb')  #=> 'lib'
  #   File.rootname('/jump.rb')     #=> '/'
  #   File.rootname('jump.rb')      #=> '.'
  #
  # CREDIT: Trans
  #
  def self.rootname(path)
    # -- this should be fairly robust
    path_re = Regexp.new('[' + Regexp.escape(File::Separator + %q{\/}) + ']')

    head, tail = path.split(path_re, 2)
    return '.' if path == head
    return '/' if head.empty?
    return head
  end

end

Version data entries

7 entries across 6 versions & 1 rubygems

Version Path
facets-2.9.3 lib/core/facets/file/rootname.rb
facets-2.9.2 lib/core/facets/file/rootname.rb
facets-2.9.2 src/core/facets/file/rootname.rb
facets-2.9.1 lib/core/facets/file/rootname.rb
facets-2.9.0 lib/core/facets/file/rootname.rb
facets-2.9.0.pre.2 lib/core/facets/file/rootname.rb
facets-2.9.0.pre.1 lib/core/facets/file/rootname.rb