简体   繁体   English

调试Ruby on Rails应用1.9.2

[英]Debugging Ruby on Rails app 1.9.2

I have been using Ruby debugger and want to be able to get stack dumps from irb. 我一直在使用Ruby调试器,希望能够从irb中获取堆栈转储。 How can I get garbage collection dumps? 如何获得垃圾收集场?
Also what patch should I use to be able to tweak the garbage collector a bit? 另外,我应该使用哪个补丁来微调垃圾收集器?

In Ruby you can re-open classes at any point and redefine them if you want. 在Ruby中,您可以随时重新打开类,并根据需要重新定义它们。 So you could re-open the GC class and add dumps or redefine any methods you want. 因此,您可以重新打开GC类并添加转储或重新定义所需的任何方法。 You also create aliases of existing methods so that you could call them again later. 您还可以创建现有方法的别名,以便以后可以再次调用它们。 For example. 例如。 if you had a class Foo with a method bar that you wanted to add some functionality to, you could do something like: 如果您有一个要添加一些功能的带有方法bar Foo类,则可以执行以下操作:

class Foo
  alias :original_bar :bar
  def bar
    # do something new
    original_bar
  end
end

So you take the original bar method and alias it to original_bar , then re-open bar and insert your custom code, then reference the original bar method again. 因此,您采用原始的bar方法并将其别名为original_bar ,然后重新打开bar并插入您的自定义代码,然后再次引用原始的bar方法。 BEHOLD THE POWER OF RUBY! 展现红宝石的力量!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM