I have a Mix-in that reflects on the receiver class to generate some code. This means that I need to execute the class method at the end of the class definition, like in this trivially dumbed down example:
module PrintMethods
module ClassMethods
def print_methods
puts instance_methods
end
end
def self.included(receiver)
receiver.extend ClassMethods
end
end
class Tester
include PrintMethods
def method_that_needs_to_print
end
print_methods
end
I'd like to have the mixin do this for me automatically, but I can't come up with a way. My first thought was to add receiver.print_methods
to self.included
in the mixin, but that won't work because the method that I want it to reflect on has not been declared yet. I could call include PrintMethods
at the end of the class, but that feels like bad form.
Are there any tricks to make this happen so I don't need to call print_methods
at the end of the class definition?