In Ruby, you can't[0] access an instance variable without an accessor; they're private by default, with all that implies. Also, when you use attr_accessor, all it does is literally[1] create a getter and a setter method. Adding logic to them later is a simple matter of replacing the attr_accessor shortcut with a method with the right name. None of the client code has to change, and that's the important part.
[0] Not quite; see Object#instance_variable_get. But that's cheating, ugly, and generally frowned upon.
[1] Not quite, but the difference is an implementation detail.
[0] Not quite; see Object#instance_variable_get. But that's cheating, ugly, and generally frowned upon.
[1] Not quite, but the difference is an implementation detail.