在使用 ruby rails 'binding.pry' 时跳过一行代码的终端命令是什么?此外,您知道进入、退出和继续的命令吗?
这是一个例子:
def add_nums
x = 5 + 5
binding.pry
x += 5
x += 7
return x
end
我想知道如何逐步执行此方法并在我的终端中查看“x”的值,直到它返回为止。谢谢
最佳答案
不优雅的解决方案
因为您可以访问 x
的范围,请手动输入每一行(或您想要的任何内容)并查看它如何影响您的变量。
更优雅的解决方案
查看 PryDebugger (MRI 1.9.2+) 或 Pry ByeBug (MRI 2+) 可让您控制手动逐步执行代码。如果您选择 ByeBug,则简要语法示例为:
def some_method
puts 'Hello World' # Run 'step' in the console to move here
end
binding.pry
some_method # Execution will stop here.
puts 'Goodbye World' # Run 'next' in the console to move here.
希望这对您有所帮助。
关于ruby-on-rails - ruby rails binding.pry怎么走,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35567947/