I want to implement a (class) method attr_accessor_with_client_reset, which does the same thing as attr_accessor, but on every writer it additionally executes
@client = nil
So, for example,
attr_accessor_with_client_reset :foo
should produce the same result as
attr_reader :foo
def foo=(value)
@foo = value
@client = nil
end
How do I achieve this?
Sergio’s solution is good, but needlessly complex: there’s no need to duplicate the behavior of
attr_reader, you can just delegate to it. And there’s no need for all this double module include hook hackery. Plus,attr_accessortakes multiple names, soattr_accessor_with_client_resetshould, too.