2

How to check if instance variable value have changed?

For global variable there is a trace_var method http://apidock.com/ruby/Kernel/trace_var

But I didn't found any information how to do that with instance variables(or class one).

I didn't use Rails.

Ruby 1.9.2.

1
  • Do you mean from inside the debugger, or in general? Commented Oct 20, 2011 at 22:39

1 Answer 1

3

The best approach might be to avoid accessing and manipulating the instance variable directly and instead go through an attr_accessor style interface.

This gives you the ability to do things like this:

def my_attr=(value)
  logger.debug("my_attr changed to #{value.inspect}")
  @my_attr = value
end
Sign up to request clarification or add additional context in comments.

Comments

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.