Created
October 1, 2019 13:25
-
-
Save havenwood/ecb7ea9fb3fdd0295038f6101841de9a to your computer and use it in GitHub Desktop.
An example for Nathanael7 on #ruby IRC
This file contains 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
def sig(method_name) | |
meth = method(method_name) | |
parameters = meth.parameters.map do |type, name| | |
case type | |
when :req | |
name | |
when :rest | |
"*#{name}" | |
when :opt | |
# Unknown default argument. | |
"#{name} = nil" | |
when :key | |
# Unknown default argument. | |
"#{name}: nil" | |
when :keyreq | |
"#{name}:" | |
when :keyrest | |
"**#{name}" | |
when :block | |
"&#{name}" | |
end | |
end | |
"def #{meth.name}(#{parameters.join(', ')})" | |
end | |
def foo(a, b = :oops, *c, d: :oops, e:, **f, &g) end | |
sig :foo | |
#=> "def foo(a, b = nil, *c, e:, d: nil, **f, &g)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment