Class: Pry::Prompt
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb
Overview
Prompt represents the Pry prompt, which can be used with Readline-like libraries. It defines a few default prompts (default prompt, simple prompt, etc) and also provides an API for adding and implementing custom prompts.
Instance Attribute Summary collapse
- #description ⇒ String readonly
- #name ⇒ String readonly
-
#prompt_procs ⇒ Array<Proc>
readonly
The array of procs that hold ‘[wait_proc, incomplete_proc]`.
Class Method Summary collapse
-
.[](name) ⇒ Hash{Symbol=>Object}
Retrieves a prompt.
-
.add(name, description = '', separators = %w[> *]) {|context, nesting, pry_instance, sep| ... } ⇒ nil
Adds a new prompt to the prompt hash.
-
.all ⇒ Hash{Symbol=>Hash}
The duplicate of the internal prompts hash.
Instance Method Summary collapse
-
#[](key) ⇒ Object
deprecated
Deprecated.
Use a ‘Pry::Prompt` instance directly
-
#incomplete_proc ⇒ Proc
The proc which builds the prompt when in the middle of an expression such as open method, etc.
-
#initialize(name, description, prompt_procs) ⇒ Prompt
constructor
A new instance of Prompt.
-
#wait_proc ⇒ Proc
The proc which builds the wait prompt (‘>`).
Constructor Details
#initialize(name, description, prompt_procs) ⇒ Prompt
Returns a new instance of Prompt.
117 118 119 120 121 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb', line 117 def initialize(name, description, prompt_procs) @name = name @description = description @prompt_procs = prompt_procs end |
Instance Attribute Details
#description ⇒ String (readonly)
108 109 110 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb', line 108 def description @description end |
#name ⇒ String (readonly)
105 106 107 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb', line 105 def name @name end |
Class Method Details
.[](name) ⇒ Hash{Symbol=>Object}
Retrieves a prompt.
52 53 54 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb', line 52 def [](name) @prompts[name.to_s] end |
.add(name, description = '', separators = %w[> *]) {|context, nesting, pry_instance, sep| ... } ⇒ nil
Adds a new prompt to the prompt hash.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb', line 79 def add(name, description = '', separators = %w[> *]) name = name.to_s unless separators.size == 2 raise ArgumentError, "separators size must be 2, given #{separators.size}" end if @prompts.key?(name) raise ArgumentError, "the '#{name}' prompt was already added" end @prompts[name] = new( name, description, separators.map do |sep| proc do |context, nesting, pry_instance| yield(context, nesting, pry_instance, sep) end end ) nil end |
Instance Method Details
#[](key) ⇒ Object
Use a ‘Pry::Prompt` instance directly
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb', line 135 def [](key) key = key.to_s if %w[name description].include?(key) Pry::Warning.warn( "`Pry::Prompt[:#{@name}][:#{key}]` is deprecated. " \ "Use `#{self.class}##{key}` instead" ) public_send(key) elsif key.to_s == 'value' Pry::Warning.warn( "`#{self.class}[:#{@name}][:value]` is deprecated. Use " \ "`#{self.class}#prompt_procs` instead or an instance of " \ "`#{self.class}` directly" ) @prompt_procs end end |
#incomplete_proc ⇒ Proc
Returns the proc which builds the prompt when in the middle of an expression such as open method, etc. (‘*`).
130 131 132 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb', line 130 def incomplete_proc @prompt_procs.last end |
#wait_proc ⇒ Proc
Returns the proc which builds the wait prompt (‘>`).
124 125 126 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/prompt.rb', line 124 def wait_proc @prompt_procs.first end |