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 ?
Asked
Active
Viewed 978 times
1 Answers
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

S.Spencer
- 581
- 3
- 8
-
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. – Kinaan Khan Sherwani Jan 31 '14 at 06:32
-
1This 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. – S.Spencer Jan 31 '14 at 17:16