get_args

Extracted from Merb, get_args allows you to query a method for its argument names and defaults.

This gem exists so you can get this functionality without having to include all of Merb.

Usage

class Dummy
  def one_arg(foo); end
  def multiple_args(foo, bar, baz); end
  def optional_args(foo, bar = 1); end
  def star_args(*foo); end
end

Dummy.instance_method(:one_arg).get_args
# => [[[:foo]], []]

Dummy.instance_method(:multiple_args).get_args
# => [[[:foo], [:bar], [:baz]], []]

Dummy.instance_method(:optional_args).get_args
# => [[[:foo], [:bar, 1]], [:bar]]

Dummy.instance_method(:star_args).get_args
# => [[[%s[*foo]]], []]

Copyright © 2009 Clinton R. Nixon. See LICENSE for details.