Class: PATH

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

Instance Method Summary collapse

Constructor Details

#initialize(*paths) ⇒ PATH

Returns a new instance of PATH



9
10
11
# File 'brew/Library/Homebrew/PATH.rb', line 9

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

Instance Method Details

#==(other) ⇒ Object



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

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



18
19
20
21
# File 'brew/Library/Homebrew/PATH.rb', line 18

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

#empty?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'brew/Library/Homebrew/PATH.rb', line 58

def empty?
  @paths.empty?
end

#existingObject



62
63
64
65
66
# File 'brew/Library/Homebrew/PATH.rb', line 62

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



23
24
25
26
# File 'brew/Library/Homebrew/PATH.rb', line 23

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

#prepend(*paths) ⇒ Object



13
14
15
16
# File 'brew/Library/Homebrew/PATH.rb', line 13

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

#reject(&block) ⇒ Object



32
33
34
# File 'brew/Library/Homebrew/PATH.rb', line 32

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

#select(&block) ⇒ Object



28
29
30
# File 'brew/Library/Homebrew/PATH.rb', line 28

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

#to_aryObject Also known as: to_a



36
37
38
# File 'brew/Library/Homebrew/PATH.rb', line 36

def to_ary
  @paths.dup.to_ary
end

#to_strObject Also known as: to_s



41
42
43
# File 'brew/Library/Homebrew/PATH.rb', line 41

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