Question

In Ruby on Rails while debugging is there any way where we can ask the debugger to break the execution as soon as a value at specific memory location or the value of a variable/object changes ?

Was it helpful?

Solution

How much of a break in execution do you want?

If the variable is set from outside the instance, then it will be being accessed via some method. You could overwrite such a method just for this purpose.

# 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top