メソッドが取れる引数のパターンをざっくり列挙するスクリプトを書いてみました。
arg_types = %w(req opt=2 keyreq: key:4 *rest **keyrest &block)
1.upto(arg_types.size) do |c|
puts
puts "--------------- arg types num #{c} ---------------"
arg_types.permutation(c).each do |l|
code = "def func(#{l.join(', ')}) end"
begin
eval(code)
puts code
rescue SyntaxError
end
end
end
実行結果
--------------- arg types num 1 ---------------
def func(req) end
def func(opt=2) end
def func(keyreq:) end
def func(key:4) end
def func(*rest) end
def func(**keyrest) end
def func(&block) end
--------------- arg types num 2 ---------------
def func(req, opt=2) end
def func(req, keyreq:) end
def func(req, key:4) end
def func(req, *rest) end
def func(req, **keyrest) end
.
.
.
--------------- arg types num 7 ---------------
def func(req, opt=2, *rest, keyreq:, key:4, **keyrest, &block) end
def func(req, opt=2, *rest, key:4, keyreq:, **keyrest, &block) end
def func(opt=2, *rest, req, keyreq:, key:4, **keyrest, &block) end
def func(opt=2, *rest, req, key:4, keyreq:, **keyrest, &block) end
抜けてるパターンもあるのですが、大体のパターンがわかります。