Class: Pathname

Inherits:
Object
  • Object
show all
Defined in:
lib/homeconf/pathname.rb

Overview

Pathname mix-ins for homeconf.

Instance Method Summary collapse

Instance Method Details

#path_prefix?(path_prefix) ⇒ Boolean

Returns whether self has the path prefix of path_prefix

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/homeconf/pathname.rb', line 8

def path_prefix?(path_prefix)
  path_parts = expand_path.parent.to_s.split(File::SEPARATOR)
  prefix_parts = File.expand_path(path_prefix).split(File::SEPARATOR)

  return false if path_parts.size < prefix_parts.size

  prefix_parts.each_with_index do |part, index|
    return false unless path_parts[index].eql? part
  end

  true
end