Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim-ruby-debugger style breakpoints with Pry in Vim

Right now, when I want a breakpoint in vim or Sublime Text, I drop a line like the following into the code:

binding.pry if Rails.env.test?

Pry (and its associated plugins) provide a nice environment in which to do interactive Ruby debugging from the command line.

However, adding actual code to my projects to create each breakpoint (and remembering to remove such code when I make commits) can be cumbersome.

I love what vim-ruby-debugger does in terms of dropping a visual breakpoint into the editor without actually modifying my project's source code, but I've had some trouble getting this to function in the context of my specs (and I'd really prefer to just use Pry 'breakpoints' in the first place).

So the question is, is it possible to drop a binding.pry reference into a file such that an editor like Vim (or Sublime Text, etc.) will pick it up and respond appropriately at debug-time without the line actually be included in the source code?

like image 496
user456584 Avatar asked May 24 '13 19:05

user456584


People also ask

How do I debug with binding pry?

To invoke the debugger, place binding. pry somewhere in your code. When the Ruby interpreter hits that code, execution stops, and you can type in commands to debug the state of the program.

How do I set breakpoints in Vim?

Breakpoints can be set in the gdb window using ordinary gdb commands. Alternatively, breakpoints can be set by navigating to a line of code in the editor window and entering :Break . Lines with breakpoints are indicated by >> in the editor window.

What is pry in Ruby?

Pry is like IRB on steroids Both IRB and Pry use REPL commands: Read, Evaluate, Print, and Loop. But Pry allows you to go further when debugging. For example, Pry gives you color-coded syntax, which helps when you're trying to figure out what will happen when code is executed.

Can you debug code in Vim?

Vim added a built-in debugger officially in version 8.1, released in May 2018. The feature had been present in some of the version 8.0 releases as well, as early as August 2017. The following vim commands load the plugin and start the debugger.


1 Answers

You can use a Git Hooks to prevent a bad commit, like leaving a binding.pry in your code.

This article explains how to do it https://launchacademy.com/blog/automatically-prevent-bad-git-commits

Here you are another good post about it http://www.ryanmcg.com/2013/8/12/another-forgotten-binding-pry/

Also I totally agree that PRY is an exceptional Gem.

like image 82
Rafa Paez Avatar answered Oct 09 '22 17:10

Rafa Paez