One style that I find myself using is to use direct access only for
writes (and try to confine writes to as few methods as possible), and
use indirect access everywhere else. An example (probably way too simple):
class C
def counters
@counters ||= {}
end
def clear_counters
@counters = nil
end
def bump_for x
counters[x] ||= 0
counters[x] += 1
end
def count_for x
counters[x] || 0
end
end