Rewriting accessor methods by a macro

Hello, I want to iterate all my entity subclasses and then iterate all their instvars and generate some method for each instvar by a macro, something like this (there are entity classes already defined in another files with My::Entityas superclass) :

module My::Entities
  {% for cls in My::Entity.subclasses %}
  class {{cls.id}}
    def hard_coded_method_just_for_testing
      puts "something"
    end

    {% for atr in @type.instance_vars %}
    def {{atr.id}}
      puts "--- getting attr #{{{atr.stringify}}}"
    end
    {% end %}
  end
  {% end %}
end

But methods in the nested for macro cycle are not generated (method hard_coded_method_just_for_testing is generated successfully for all classes), so iteration over subclasses is OK, but iteration over their instvars does nothing.

Thanks very much for advice.

This is not possible to do. When macros run outside of methods instance vars of classes are not yet known.

OK, thanks.

Is there any way, that I can redefine existing getters of various existing classes with my new implementation (automatically, by a macro, not by hard-coding it one-by-one of course)?

I want to inject some fucntionality into existing property getters/setters (something like before/after aspects with the ability to ignore original getter/setter implementation)?