Skip to content

Instantly share code, notes, and snippets.

@BanzaiMan
Last active September 13, 2019 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BanzaiMan/a443f10f546847b7d4f23963203e1670 to your computer and use it in GitHub Desktop.
Save BanzaiMan/a443f10f546847b7d4f23963203e1670 to your computer and use it in GitHub Desktop.
Get the list of arguments passed to the current method
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