lib/rdoc/any_method.rb in rdoc-4.0.1 vs lib/rdoc/any_method.rb in rdoc-4.1.0.preview.3

- old
+ new

@@ -7,12 +7,15 @@ # 2:: # RDoc 4 # Added calls_super # Added parent name and class # Added section title + # 3:: + # RDoc 4.1 + # Added is_alias_for - MARSHAL_VERSION = 2 # :nodoc: + MARSHAL_VERSION = 3 # :nodoc: ## # Don't rename \#initialize to \::new attr_accessor :dont_rename_initialize @@ -23,11 +26,11 @@ attr_accessor :c_function ## # Different ways to call this method - attr_accessor :call_seq + attr_reader :call_seq ## # Parameters for this method attr_accessor :params @@ -88,17 +91,54 @@ "#{name}#{param_seq}" end end ## + # Sets the different ways you can call this method. If an empty +call_seq+ + # is given nil is assumed. + # + # See also #param_seq + + def call_seq= call_seq + return if call_seq.empty? + + @call_seq = call_seq + end + + ## + # Loads is_alias_for from the internal name. Returns nil if the alias + # cannot be found. + + def is_alias_for # :nodoc: + case @is_alias_for + when RDoc::MethodAttr then + @is_alias_for + when Array then + return nil unless @store + + klass_name, singleton, method_name = @is_alias_for + + return nil unless klass = @store.find_class_or_module(klass_name) + + @is_alias_for = klass.find_method method_name, singleton + end + end + + ## # Dumps this AnyMethod for use by ri. See also #marshal_load def marshal_dump aliases = @aliases.map do |a| [a.name, parse(a.comment)] end + is_alias_for = [ + @is_alias_for.parent.full_name, + @is_alias_for.singleton, + @is_alias_for.name + ] if @is_alias_for + [ MARSHAL_VERSION, @name, full_name, @singleton, @visibility, @@ -110,10 +150,11 @@ @file.relative_name, @calls_super, @parent.name, @parent.class, @section.title, + is_alias_for, ] end ## # Loads this AnyMethod from +array+. For a loaded AnyMethod the following @@ -124,11 +165,10 @@ def marshal_load array initialize_visibility @dont_rename_initialize = nil - @is_alias_for = nil @token_stream = nil @aliases = [] @parent = nil @parent_name = nil @parent_class = nil @@ -148,10 +188,11 @@ # 10 handled below @calls_super = array[11] @parent_name = array[12] @parent_title = array[13] @section_title = array[14] + @is_alias_for = array[15] array[8].each do |new_name, comment| add_alias RDoc::Alias.new(nil, @name, new_name, comment, @singleton) end @@ -172,10 +213,13 @@ # If the method has no assigned name, it extracts it from #call_seq. def name return @name if @name - @name = @call_seq[/^.*?\.(\w+)/, 1] || @call_seq if @call_seq + @name = + @call_seq[/^.*?\.(\w+)/, 1] || + @call_seq[/^.*?(\w+)/, 1] || + @call_seq if @call_seq end ## # A list of this method's method and yield parameters. +call-seq+ params # are preferred over parsed method and block params.