Class: PATH

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
Library/Homebrew/PATH.rb

Instance Method Summary collapse

Constructor Details

#initialize(*paths) ⇒ PATH

Returns a new instance of PATH



7
8
9
# File 'Library/Homebrew/PATH.rb', line 7

def initialize(*paths)
  @paths = parse(*paths)
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'Library/Homebrew/PATH.rb', line 44

def ==(other)
  if other.respond_to?(:to_ary)
    return true if to_ary == other.to_ary
  end

  if other.respond_to?(:to_str)
    return true if to_str == other.to_str
  end

  false
end

#append(*paths) ⇒ Object



16
17
18
19
# File 'Library/Homebrew/PATH.rb', line 16

def append(*paths)
  @paths = parse(*@paths, *paths)
  self
end

#empty?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'Library/Homebrew/PATH.rb', line 56

def empty?
  @paths.empty?
end

#existingObject



60
61
62
63
64
# File 'Library/Homebrew/PATH.rb', line 60

def existing
  existing_path = select(&File.method(:directory?))
  # return nil instead of empty PATH, to unset environment variables
  existing_path unless existing_path.empty?
end

#insert(index, *paths) ⇒ Object



21
22
23
24
# File 'Library/Homebrew/PATH.rb', line 21

def insert(index, *paths)
  @paths = parse(*@paths.insert(index, *paths))
  self
end

#prepend(*paths) ⇒ Object



11
12
13
14
# File 'Library/Homebrew/PATH.rb', line 11

def prepend(*paths)
  @paths = parse(*paths, *@paths)
  self
end

#reject(&block) ⇒ Object



30
31
32
# File 'Library/Homebrew/PATH.rb', line 30

def reject(&block)
  self.class.new(@paths.reject(&block))
end

#select(&block) ⇒ Object



26
27
28
# File 'Library/Homebrew/PATH.rb', line 26

def select(&block)
  self.class.new(@paths.select(&block))
end

#to_aryObject Also known as: to_a



34
35
36
# File 'Library/Homebrew/PATH.rb', line 34

def to_ary
  @paths
end

#to_strObject Also known as: to_s



39
40
41
# File 'Library/Homebrew/PATH.rb', line 39

def to_str
  @paths.join(File::PATH_SEPARATOR)
end