Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Ruby/Rails调试:对象/变量的值更改时中断_Ruby On Rails_Ruby_Ruby Debug - Fatal编程技术网

Ruby on rails Ruby/Rails调试:对象/变量的值更改时中断

Ruby on rails Ruby/Rails调试:对象/变量的值更改时中断,ruby-on-rails,ruby,ruby-debug,Ruby On Rails,Ruby,Ruby Debug,在RubyonRails中,当调试时,有没有任何方法可以让调试器在特定内存位置的值或变量/对象的值发生变化时立即中断执行?您希望执行中断多少 如果变量是从实例外部设置的,那么将通过某种方法访问它。您可以为此目的覆盖这样的方法 # define class Foo def bar @bar ||= 'default' end def bar=(value) @bar = value end end # overwrite class Foo def bar=

在RubyonRails中,当调试时,有没有任何方法可以让调试器在特定内存位置的值或变量/对象的值发生变化时立即中断执行?

您希望执行中断多少

如果变量是从实例外部设置的,那么将通过某种方法访问它。您可以为此目的覆盖这样的方法

# define
class Foo
  def bar
    @bar ||= 'default'
  end

  def bar=(value)
    @bar = value
  end
end

# overwrite
class Foo
  def bar=(value)
    super
    abort("Message goes here")
  end
end

在我的情况下,我不知道值在哪里变化。i、 e.我不知道发生更改的代码的确切功能/位置。因此,我想使用调试器的这种功能(如果可用的话),每当该值发生变化时,调试器就会中断执行,我将能够找到特定的代码段。这只是一种查找从何处调用变化的策略的指示。如果它是实例内部的,那么可以确保所有对变量的访问都通过getter/setter方法进行。如果它来自外部调用,那么类似的推理也适用。但是,如果数据正在随db表的批量更新而更改,则所有下注都将关闭。