I know the debugger gem is not and never will be compatible with ruby 2.0 per "officially support ruby 2.X".

In the changelog of Ruby 2.0 is:

Debug support

DTrace support, which enables run-time diagnosis in

production TracePoint, which is an improved tracing API

Is there something out of the box for debugging with Ruby 2.0? Can somebody explain this to me?

有帮助吗?

解决方案

The debugger gem can be used but it still has issues.

Install byebug which was written for Ruby 2.0 debugging.

For breakpoints, use the byebug command in your code instead of debugger.

其他提示

Version 1.4.0 of the debugger gem now installs without problems. There are still some issues but this should be fixed soon.

The debugger gem does not play well with Ruby 2. Instead, install the Byebug gem that is fully compatible with Ruby 2.

Use pry:

gem install pry  
gem install pry-debugger

See "Debugging Ruby With Pry".

debug.rb (aka binding.break)

Consider using a new Ruby debugging tool called debug.rb.

It supports syntax highlighting and many more out-of-the-box.

Also, it is worth mentioning that it is developed by the Ruby core team.

Just place binding.break anywhere in your codebase.

Here is an example:

binding.break example

Also, it is a default Rails debugger starting from version 7.

Notes:

  • Do not forget about require 'debug'
  • q # quit command

Sources:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top