How to get instance variables of external class/struct?

I am trying to get properties of a struct/class and adding those to a new class. But looks like instance_vars macro only works to get property of self and not work for other classes. Any suggestion to achieve this?


struct Node
  property name = "", endpoint = ""
end

struct Pool
  property name = ""
end

# Expected
# struct PoolView
#   property name = "", node_name = "", node_endpoint = ""
# end
struct PoolView
  property name = ""

  {% for v in Node.instance_vars %}
    property {{ ("node_" + v.name.stringify).id }} = {{ v.default_value }}
  {% end %}
end

pool_view = PoolView.new
puts pool_view
# Output:
# PoolView(@name="")

The instance_vars method only works in the context of a method (either class or instance). Best bet would be to just copy the properties over manually, or define them in a module and include them into both contexts.

EDIT: Ofc you could get fancier, but IMO is a point where the extra complexity isn’t worth duplicating a few lines.

Thanks