Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pry Error: Cannot find local context. Did you use `binding.pry`?

Tags:

Why am I getting this pry error?

[36] pry(main)> s = "pry" Error: Cannot find local context. Did you use `binding.pry`? 

It works fine in this screencast http://pryrepl.org/

like image 690
Snowcrash Avatar asked Mar 27 '15 16:03

Snowcrash


People also ask

How do I exit binding pry?

Note: You must exit out of the current pry session by typing exit at the pry prompt and then re-run your file by entering ruby your_file_name. rb again in your terminal.

How do you use binding pry?

The Ruby programmer can invoke the pry console during runtime by inserting the line 'binding. pry' wherever they would like to stop the program. When the interpreter hits the binding. pry, Pry will open a REPL session in the console, allowing you to test variables, return values, iterations, and more.

How does pry work?

pry is essentially 'prying' into the current binding or context of the code, from outside your file. So when you place the line binding. pry in your code, that line will get interpreted at runtime (as your program is executed).


1 Answers

It seems that s, c and n are reserved commands on the pry-nav gem, found here, that help you to step through bindings.

Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'

They are set up by default but can be removed by putting:

Pry::Commands.delete 'c'
Pry::Commands.delete 'n'
Pry::Commands.delete 's'

in a file called .pryrc in your root directory.

like image 65
Travis Yoder Avatar answered Sep 17 '22 14:09

Travis Yoder