I’m trying to configure a simpler Pry prompt for entering Ruby code. What does nest_level mean? The Pry documentation says, “Three parameters are passed into the prompt procs, the object that is the target of the session, the current nesting level, and a reference to the associated Pry instance. These objects can be used in the prompt, if desired.” Their example is:
Pry.config.prompt = proc { |obj, nest_level, _| "#{obj}:#{nest_level}> " }
However, nest_level doesn’t seem to be what I think it is:
main:0> if true
main:0> if true
main:0> while true
main:0> puts 1
main:0> break
main:0> end
main:0> end
main:0> end
1
=> nil
main:0>
The nesting level refers the scope. In
pry, you can use thecdcommand to “enter” objects, which is like usinginstance_eval– allowing you to use methods of said object without prefixing them with the object’s name. For example(with the same prompt proc you used):I’ve
cded into the array, and called it’s method without prefixing them witharr.. The nesting level was changed to 1 when Icded into it, and went back to 0 when Iexited. I could also usecd ..to exit the scope.