Ok, this actually easy, because they can both do:
def attribute=(new_value)
# stuff
super
end
and all mixed in definitions will get called.
I was led astray by the fact that all the examples of overriding an
attribute writer have it calling write_attribute so I sillily thought
that super would return a nomethoderror in the last mixin in the
chain. But in actual fact you can just call super in an overridden
attribute write, you don’t have to call write_attribute (unless
someone knows a reason you do???).
However, figuring out what to do if you couldn’t count on the method
being mixed_in already having a definition in the superclass helped
me to learn more about ruby. Here is my example, in case anyone is
curious:
class Superthing #this stands in for ActiveRecord::Base
def dohook
puts “whatever happens, this must happen”
end
end
module Doer #this is in one file in a plugin
module Mary
def doit
puts “Mary says doit”
super
end
end
end
module Doer # this is in another file in a plugin, and is somewhat
orthogonal to “Mary”
module Bob
def doit
puts “Bob says doit”
super
end
end
end
module Doer # this initializes the plugin
def self.included(base)
base.extend SetupMethods
end
module MakeSureTheresASuper # this is necessary because the
superclass only defines “dohook” not “doit”
def doit
dohook
end
end
module SetupMethods
def setmeup
include MakeSureTheresASuper
if rand(2) == 1
puts “Bob first”
include Bob
include Mary
else
puts “Mary first”
include Mary
include Bob
end
end
end
end
Superthing.send(:include, Doer::SetupMethods)
class Thing < Superthing
include Doer
setmeup
def initialize()
end
end
#will always do Bob & will always do Mary, but order is random
Thing.new.doit