I don’t think there’s a real great way to automatically do this to all methods. You’re best bet would be one of the following:
- Abstract the
.recordSystemCall
call to a macro itself, so just have to writeIsm.record_system_call
and thats it. - Create a macro that accepts a method definition, rebuild the method definition with the extra line. Something like:
macro instrument(a_def)
def {{a_def.name.id}}({{a_def.args.splat}}) {% unless a_def.return_type.is_a?(Nop) %}: {{a_def.return_type}}{% end %}
Ism.record_system_call(command: \{{ "#{@def.receiver.id}.#{@def.name.id}" }})
{{a_def.body}}
end
end
instrument def test
pp "foo"
end
Would need to be sure you handle blocks as well.
- Make use of some TBD feature like [RFC] Annotations metadata declaration/DSL - #9 by HertzDevil to make the second option a bit simpler/declarative.