Class: Prompt::Parameter
- Inherits:
-
Object
- Object
- Prompt::Parameter
- Defined in:
- lib/prompt/parameter.rb
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #clear_cached_values ⇒ Object
- #completions(starting_with = "") ⇒ Object
-
#initialize(name, desc = nil, values = nil, &block) ⇒ Parameter
constructor
A new instance of Parameter.
Constructor Details
#initialize(name, desc = nil, values = nil, &block) ⇒ Parameter
Returns a new instance of Parameter.
7 8 9 10 11 12 13 |
# File 'lib/prompt/parameter.rb', line 7 def initialize(name, desc = nil, values = nil, &block) @name = name @desc = desc @values = values || [] @proc = block if block_given? @cached_values = {} end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
5 6 7 |
# File 'lib/prompt/parameter.rb', line 5 def desc @desc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/prompt/parameter.rb', line 4 def name @name end |
Instance Method Details
#clear_cached_values ⇒ Object
15 16 17 |
# File 'lib/prompt/parameter.rb', line 15 def clear_cached_values @cached_values = {} end |
#completions(starting_with = "") ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/prompt/parameter.rb', line 19 def completions(starting_with = "") all = if @proc @cached_values[starting_with] ||= @proc.call(starting_with) else @values end all.map(&:to_s).grep /^#{starting_with}/ end |