Your destroy
, destroyfoo
and changefoo
methods are all just assigning to a local variable and do not result in a call to the accessor method.
The reason that the change
method works is because conf['foo']['bar'] = 'meh'
is a call to the conf
method to get @conf
, then a call to the []
method on the object returned, then a call to the []=
method on the first level hash. Likewise for add
.
This is different to a direct assignment like conf =
Also, for completeness, note that even if you'd created an attr writer for @conf
(either using attr_writer
or by writing a conf=
method yourself) then a line like conf = nil
would still be referring to a local variable and wouldn't call your method. You'd need to use self.conf=
in order to disambiguate.