class TTY::Prompt::Choices

@api private
A class responsible for storing a collection of choices

def self.[](*choices)

Other tags:
    Api: - public

Returns:
  • (Choices) -

Parameters:
  • choices (Array[Object]) --
def self.[](*choices)
  new(choices)
end

def <<(choice)

Other tags:
    Api: - public

Parameters:
  • choice (Object) --
def <<(choice)
  choices << Choice.from(choice)
end

def [](index)

Other tags:
    Api: - public

Returns:
  • (Choice) -

Parameters:
  • index (Integer) --
def [](index)
  @choices[index]
end

def each(&block)

Other tags:
    Api: - public

Other tags:
    Yield: -
def each(&block)
  return to_enum unless block_given?
  choices.each(&block)
end

def enabled

Other tags:
    Api: - public
def enabled
  reject(&:disabled?)
end

def enabled_indexes

def enabled_indexes
  each_with_index.reduce([]) do |acc, (choice, idx)|
    acc << idx unless choice.disabled?
    acc
  end
end

def find_by(attr, value)

Other tags:
    Api: - public

Returns:
  • (Choice) -

Parameters:
  • value (Object) --
  • attr (Symbol) --
def find_by(attr, value)
  find { |choice| choice.public_send(attr) == value }
end

def initialize(choices = [])

Other tags:
    Api: - public

Parameters:
  • choices (Array[Choice]) --
def initialize(choices = [])
  @choices = choices.map do |choice|
    Choice.from(choice)
  end
end

def pluck(name)

Other tags:
    Api: - public

Returns:
  • (Choice) -

Parameters:
  • name (String) --
def pluck(name)
  map { |choice| choice.public_send(name) }
end