4

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 ?

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

In my case I don't know where the value is changing. i.e. i don't know about the exact function/location of the code where the change happening. So I wanted to use such functionality of debugger ( if available ) that whenever that value changes the debugger breaks execution and i will be able to locate that particular piece of code.
This is just an indication of a strategy for finding where the change is being called from. If it is internal to the instance, you could ensure all access to the variable goes though the getter/setter methods. If it is from an external call, then a similar line of reasoning applies. If, however, the data is being changed with a bulk update of the db table, then all bets are off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.