rb_scan_args(method_body)
public
Extracts parameters from the method_body and returns a method
parameter string. Follows 1.9.3dev’s scan-arg-spec, see README.EXT
Show source
def rb_scan_args method_body
method_body =~ /rb_scan_args\((.*?)\)/
return '(*args)' unless $1
$1.split(/,/)[2] =~ /"(.*?)"/
format = $1.split(//)
lead = opt = trail = 0
if format.first =~ /\d/ then
lead = $&.to_i
format.shift
if format.first =~ /\d/ then
opt = $&.to_i
format.shift
if format.first =~ /\d/ then
trail = $&.to_i
format.shift
block_arg = true
end
end
end
if format.first == '*' and not block_arg then
var = true
format.shift
if format.first =~ /\d/ then
trail = $&.to_i
format.shift
end
end
if format.first == ':' then
hash = true
format.shift
end
if format.first == '&' then
block = true
format.shift
end
args = []
position = 1
(1...(position + lead)).each do |index|
args << "p#{index}"
end
position += lead
(position...(position + opt)).each do |index|
args << "p#{index} = v#{index}"
end
position += opt
if var then
args << '*args'
position += 1
end
(position...(position + trail)).each do |index|
args << "p#{index}"
end
position += trail
if hash then
args << "p#{position} = {}"
position += 1
end
args << '&block' if block
"(#{args.join ', '})"
end