lib/rdoc/any_method.rb in rdoc-2.5 vs lib/rdoc/any_method.rb in rdoc-2.5.1

- old
+ new

@@ -4,11 +4,11 @@ ## # AnyMethod is the base class for objects representing methods class RDoc::AnyMethod < RDoc::CodeObject - MARSHAL_VERSION = 0 # :nodoc: + MARSHAL_VERSION = 1 # :nodoc: include Comparable ## # Method name @@ -56,11 +56,11 @@ attr_accessor :is_alias_for ## # Parameters for this method - attr_overridable :params, :param, :parameters, :parameter + attr_accessor :params ## # Different ways to call this method attr_accessor :call_seq @@ -85,10 +85,11 @@ @aliases = [] @block_params = nil @call_seq = nil @dont_rename_initialize = false @is_alias_for = nil + @params = nil @parent_name = nil @singleton = nil @token_stream = nil @visibility = :public @@ -109,10 +110,23 @@ def add_alias(method) @aliases << method end ## + # The call_seq or the param_seq with method name, if there is no call_seq. + # + # Use this for displaying a method's argument lists. + + def arglists + if @call_seq then + @call_seq + elsif @params then + "#{name}#{param_seq}" + end + end + + ## # HTML id-friendly method name def html_name @name.gsub(/[^a-z]+/, '-') end @@ -149,10 +163,11 @@ @visibility, parse(@comment), @call_seq, @block_params, aliases, + @params, ] end ## # Loads this AnyMethod from +array+. For a loaded AnyMethod the following @@ -160,11 +175,10 @@ # # * #full_name # * #parent_name def marshal_load(array) - @aliases = [] @dont_rename_initialize = nil @is_alias_for = nil @token_stream = nil @name = array[1] @@ -172,10 +186,12 @@ @singleton = array[3] @visibility = array[4] @comment = array[5] @call_seq = array[6] @block_params = array[7] + @aliases = array[8] + @params = array[9] @parent_name = if @full_name =~ /#/ then $` else name = @full_name.split('::') @@ -199,19 +215,19 @@ ## # Pretty parameter list for this method def param_seq - params = params.gsub(/\s*\#.*/, '') + params = @params.gsub(/\s*\#.*/, '') params = params.tr("\n", " ").squeeze(" ") - params = "(#{params})" unless p[0] == ?( + params = "(#{params})" unless params[0] == ?( - if block = block_params then # yes, = + if @block_params then # If this method has explicit block parameters, remove any explicit # &block - params.sub!(/,?\s*&\w+/) + params.sub!(/,?\s*&\w+/, '') - block.gsub!(/\s*\#.*/, '') + block = @block_params.gsub(/\s*\#.*/, '') block = block.tr("\n", " ").squeeze(" ") if block[0] == ?( block.sub!(/^\(/, '').sub!(/\)/, '') end params << " { |#{block}| ... }"