Kinaan Khan Sherwani
Kinaan Khan Sherwani

Reputation: 1534

Ruby/Rails Debugging: Break when a value of an object/variable changes

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 ?

Upvotes: 4

Views: 1063

Answers (1)

S.Spencer
S.Spencer

Reputation: 611

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

Upvotes: 3

Related Questions