I'm trying to override a dynamically-generated method by including a module.
In the example below, a Ripple association adds a rows=
method to Table. I want to call that method, but also do some additional stuff afterwards.
I created a module to override the method, thinking that the module's row=
would be able to call super
to use the existing method.
class Table
# Ripple association - creates rows= method
many :rows, :class_name => Table::Row
# Hacky first attempt to use the dynamically-created
# method and also do additional stuff - I would actually
# move this code elsewhere if it worked
module RowNormalizer
def rows=(*args)
rows = super
rows.map!(&:normalize_prior_year)
end
end
include RowNormalizer
end
However, my new rows=
is never called, as evidenced by the fact that if I raise an exception inside it, nothing happens.
I know the module is getting included, because if I put this in it, my exception gets raised.
included do
raise 'I got included, woo!'
end
Also, if instead of rows=
, the module defines somethingelse=
, that method is callable.
Why isn't my module method overriding the dynamically-generated one?