Let’s suppose I have a function that I do not know the arguments to. How could I go about obtaining the names and values of the arguments given to the function (when running inside it)?
For example:
def foo(a, b) do
vars = magically_get_vars(...)
end
When called as foo(1, 2)
, vars
would be set to a mapping such as [a: 1, b: 2]
.
I know that with __ENV__.vars
I can get the names of the visible variables (which is fine too), but it does not contain the values. How do I obtain the values as well?
The real use case is an EEx layout that has no knowledge of the arguments passed to it but must pass those arguments on (this has to do with Raxx layouts and views). But I figured getting an answer to this more generic question would be interesting as well.