Class: TTY::Prompt::Choices Private
- Inherits:
-
Object
- Object
- TTY::Prompt::Choices
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/tty/prompt/choices.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A class responsible for storing a collection of choices
Instance Attribute Summary collapse
-
#choices ⇒ Array[Choice]
readonly
The actual collection choices.
Class Method Summary collapse
-
.[](*choices) ⇒ Choices
Convenience for creating choices.
Instance Method Summary collapse
-
#<<(choice) ⇒ Object
Add choice to collection.
-
#[](index) ⇒ Choice
Access choice by index.
-
#each {|Choice| ... } ⇒ Object
Iterate over all choices in the collection.
-
#find_by(attr, value) ⇒ Choice
Find a matching choice.
-
#initialize(choices = []) ⇒ Choices
constructor
Create Choices collection.
-
#pluck(name) ⇒ Choice
Pluck a choice by its name from collection.
Constructor Details
Instance Attribute Details
#choices ⇒ Array[Choice] (readonly)
The actual collection choices
21 22 23 |
# File 'lib/tty/prompt/choices.rb', line 21 def choices @choices end |
Class Method Details
.[](*choices) ⇒ Choices
Convenience for creating choices
34 35 36 |
# File 'lib/tty/prompt/choices.rb', line 34 def self.[](*choices) new(choices) end |
Instance Method Details
#<<(choice) ⇒ Object
Add choice to collection
66 67 68 |
# File 'lib/tty/prompt/choices.rb', line 66 def <<(choice) choices << Choice.from(choice) end |
#[](index) ⇒ Choice
Access choice by index
77 78 79 |
# File 'lib/tty/prompt/choices.rb', line 77 def [](index) @choices[index] end |
#each {|Choice| ... } ⇒ Object
Iterate over all choices in the collection
55 56 57 58 |
# File 'lib/tty/prompt/choices.rb', line 55 def each(&block) return to_enum unless block_given? choices.each(&block) end |
#find_by(attr, value) ⇒ Choice
Find a matching choice
105 106 107 |
# File 'lib/tty/prompt/choices.rb', line 105 def find_by(attr, value) find { |choice| choice.public_send(attr) == value } end |
#pluck(name) ⇒ Choice
Pluck a choice by its name from collection
89 90 91 |
# File 'lib/tty/prompt/choices.rb', line 89 def pluck(name) map { |choice| choice.public_send(name) } end |