G
Gavin Sinclair
Something I've wanted to do on a few occasions recently is to evaluate
an expression in the context of the calling method. A simple example
is this:
def trace(expr, _binding)
LOG.debug "#{expr} = #{eval expr, _binding)}"
end
def something
x = 5
y = 7
trace "x + y", binding
end
The effect of calling something() now is that the message "x + y = 12"
gets logged.
It Would Be Nice if I could do this instead:
def trace(expr)
_binding = somehow_get_calling_methods_binding()
LOG.debug "#{expr} = #{eval expr, _binding)}"
end
def something
x = 5
y = 7
trace "x + y"
end
Is there a substitute for "somehow_get_calling_methods_binding()" in
the code above?
Thanks,
Gavin
an expression in the context of the calling method. A simple example
is this:
def trace(expr, _binding)
LOG.debug "#{expr} = #{eval expr, _binding)}"
end
def something
x = 5
y = 7
trace "x + y", binding
end
The effect of calling something() now is that the message "x + y = 12"
gets logged.
It Would Be Nice if I could do this instead:
def trace(expr)
_binding = somehow_get_calling_methods_binding()
LOG.debug "#{expr} = #{eval expr, _binding)}"
end
def something
x = 5
y = 7
trace "x + y"
end
Is there a substitute for "somehow_get_calling_methods_binding()" in
the code above?
Thanks,
Gavin