Last active
September 13, 2019 17:16
-
-
Save BanzaiMan/a443f10f546847b7d4f23963203e1670 to your computer and use it in GitHub Desktop.
Get the list of arguments passed to the current method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BasicObject | |
def __arguments__(bdg) | |
method_symbol = caller(1,1).first.match(/\`(?<name>[^']*)'/)[:name].to_sym | |
self.method(method_symbol).parameters.map { |e| [e[1], bdg.local_variable_get(e[1])] } | |
end | |
end | |
def foo(a, b='c', *d, e:, f: "foo", **g) | |
__arguments__(binding) | |
end | |
foo("first", e: "keyword!") # => [[:a, "first"], [:b, "c"], [:d, []], [:e, "keyword!"], [:f, "foo"], [:g, {}]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment