Class: Options

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
brew/Library/Homebrew/options.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Options

Returns a new instance of Options



65
66
67
# File 'brew/Library/Homebrew/options.rb', line 65

def initialize(*args)
  @options = Set.new(*args)
end

Class Method Details

.create(array) ⇒ Object



61
62
63
# File 'brew/Library/Homebrew/options.rb', line 61

def self.create(array)
  new array.map { |e| Option.new(e[/^--([^=]+=?)(.+)?$/, 1] || e) }
end

Instance Method Details

#&(other) ⇒ Object



86
87
88
# File 'brew/Library/Homebrew/options.rb', line 86

def &(other)
  self.class.new(@options & other)
end

#*(other) ⇒ Object



94
95
96
# File 'brew/Library/Homebrew/options.rb', line 94

def *(other)
  @options.to_a * other
end

#+(other) ⇒ Object



78
79
80
# File 'brew/Library/Homebrew/options.rb', line 78

def +(other)
  self.class.new(@options + other)
end

#-(other) ⇒ Object



82
83
84
# File 'brew/Library/Homebrew/options.rb', line 82

def -(other)
  self.class.new(@options - other)
end

#<<(other) ⇒ Object



73
74
75
76
# File 'brew/Library/Homebrew/options.rb', line 73

def <<(other)
  @options << other
  self
end

#as_flagsObject



102
103
104
# File 'brew/Library/Homebrew/options.rb', line 102

def as_flags
  map(&:flag)
end

#each(*args, &block) ⇒ Object



69
70
71
# File 'brew/Library/Homebrew/options.rb', line 69

def each(*args, &block)
  @options.each(*args, &block)
end

#empty?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'brew/Library/Homebrew/options.rb', line 98

def empty?
  @options.empty?
end

#include?(o) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'brew/Library/Homebrew/options.rb', line 106

def include?(o)
  any? { |opt| opt == o || opt.name == o || opt.flag == o }
end

#inspectObject



112
113
114
# File 'brew/Library/Homebrew/options.rb', line 112

def inspect
  "#<#{self.class.name}: #{to_a.inspect}>"
end

#|(other) ⇒ Object



90
91
92
# File 'brew/Library/Homebrew/options.rb', line 90

def |(other)
  self.class.new(@options | other)
end