有没有一种快速的方法可以找出哪些变量适用于当前作用域,哪些对象'self'在Ruby on Rails中引用?
Mat*_*sel 25
我认为这pry是一个很好的解决方案,但debugger正如@jvnill建议的那样,它也有效.
gem install pry # or add to bundler
Run Code Online (Sandbox Code Playgroud)
在您的代码中,您需要在检查范围的任何地方添加以下内容:
require 'pry'
binding.pry # this will open a console view with the binding as the current scope
Run Code Online (Sandbox Code Playgroud)
在pry你所要求的内容中有一些东西:
pry> ls
Run Code Online (Sandbox Code Playgroud)
ls 将显示可以调用的变量和方法,以及它们来自哪些对象/类.
pry> self # will return self in the current context
pry> pry-backtrace # shows the current stack
pry> help # will show the list of commands
pry> cd <some obj> # will change the scope to the target object
pry> exit # move back out to previous console scope
Run Code Online (Sandbox Code Playgroud)
澄清你是否在寻找完全不同的东西.
我真的很喜欢使用 Better Errors gem,然后我只需在需要的地方“raise @somevar”,这样我就可以在浏览器控制台中使用并用棍子戳它。:) 天哪,我喜欢那东西。
| 归档时间: |
|
| 查看次数: |
5750 次 |
| 最近记录: |