method
rb_scan_args
v1_9_3_392 -
Show latest stable
- Class:
RDoc::Parser::C
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
# File lib/rdoc/parser/c.rb, line 935
def rb_scan_args method_body
method_body =~ /rb_scan_args\((.*?)\)/
return '(*args)' unless $1
$1.split(/,/)[2] =~ /"(.*?)"/ # format argument
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
# if the format string is not empty there's a bug in the C code, ignore it
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 Related methods
- Instance methods
- do_aliases
- do_attrs
- do_classes
- do_constants
- do_includes
- do_methods
- find_alias_comment
- find_attr_comment
- find_body
- find_class
- find_class_comment
- find_const_comment
- find_modifiers
- find_override_comment
- handle_attr
- handle_class_module
- handle_constants
- handle_ifdefs_in
- handle_method
- handle_singleton
- handle_tab_width
- look_for_directives_in
- rb_scan_args
- remove_commented_out_lines
- remove_private_comments
- scan
- Class methods
- new
- reset