Skip to content

Instantly share code, notes, and snippets.

@careo
Created March 26, 2010 22:11
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 careo/345468 to your computer and use it in GitHub Desktop.
Save careo/345468 to your computer and use it in GitHub Desktop.
class Foo
def bar(arg)
end
def baz(arg=nil)
end
def frobnicate(*arg)
end
def blocky(&block)
end
def hairy(first,second=2,*middle,last)
end
end
foo = Foo.new
(foo.methods - Object.new.methods).each do |name|
m = foo.method(name)
p [name, m.parameters]
end
# => [:bar, [[:req, :arg]]]
# => [:baz, [[:opt, :arg]]]
# => [:frobnicate, [[:rest, :arg]]]
# => [:blocky, [[:block, :block]]]
procy = proc {|first,second=2,*middle,last| }
p procy.parameters
# => [[:opt, :first], [:opt, :second], [:rest, :middle], [:opt, :last]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment