Class: Options

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Options

Returns a new instance of Options



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

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

Class Method Details

.create(array) ⇒ Object



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

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

Instance Method Details

#&(other) ⇒ Object



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

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

#*(other) ⇒ Object



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

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

#+(other) ⇒ Object



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

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

#-(other) ⇒ Object



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

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

#<<(other) ⇒ Object



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

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

#as_flagsObject



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

def as_flags
  map(&:flag)
end

#each(*args, &block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @options.empty?
end

#include?(o) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#inspectObject



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

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

#|(other) ⇒ Object



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

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