lib/rdoc/any_method.rb in rdoc-2.4.3 vs lib/rdoc/any_method.rb in rdoc-2.5
- old
+ new
@@ -4,10 +4,14 @@
##
# AnyMethod is the base class for objects representing methods
class RDoc::AnyMethod < RDoc::CodeObject
+ MARSHAL_VERSION = 0 # :nodoc:
+
+ include Comparable
+
##
# Method name
attr_writer :name
@@ -72,19 +76,23 @@
reset
def initialize(text, name)
super()
+
@text = text
@name = name
- @token_stream = nil
- @visibility = :public
+
+ @aliases = []
+ @block_params = nil
+ @call_seq = nil
@dont_rename_initialize = false
- @block_params = nil
- @aliases = []
- @is_alias_for = nil
- @call_seq = nil
+ @is_alias_for = nil
+ @parent_name = nil
+ @singleton = nil
+ @token_stream = nil
+ @visibility = :public
@aref = @@aref
@@aref = @@aref.succ
end
@@ -109,34 +117,86 @@
@name.gsub(/[^a-z]+/, '-')
end
def inspect # :nodoc:
alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
- "#<%s:0x%x %s%s%s (%s)%s>" % [
- self.class, object_id,
- parent_name,
- singleton ? '::' : '#',
- name,
- visibility,
- alias_for,
- ]
+ "#<%s:0x%x %s (%s)%s>" % [
+ self.class, object_id,
+ full_name,
+ visibility,
+ alias_for,
+ ]
end
##
# Full method name including namespace
def full_name
- "#{@parent.full_name}#{pretty_name}"
+ @full_name ||= "#{@parent ? @parent.full_name : '(unknown)'}#{pretty_name}"
end
##
+ # Dumps this AnyMethod for use by ri. See also #marshal_load
+
+ def marshal_dump
+ aliases = @aliases.map do |a|
+ [a.full_name, parse(a.comment)]
+ end
+
+ [ MARSHAL_VERSION,
+ @name,
+ full_name,
+ @singleton,
+ @visibility,
+ parse(@comment),
+ @call_seq,
+ @block_params,
+ aliases,
+ ]
+ end
+
+ ##
+ # Loads this AnyMethod from +array+. For a loaded AnyMethod the following
+ # methods will return cached values:
+ #
+ # * #full_name
+ # * #parent_name
+
+ def marshal_load(array)
+ @aliases = []
+ @dont_rename_initialize = nil
+ @is_alias_for = nil
+ @token_stream = nil
+
+ @name = array[1]
+ @full_name = array[2]
+ @singleton = array[3]
+ @visibility = array[4]
+ @comment = array[5]
+ @call_seq = array[6]
+ @block_params = array[7]
+
+ @parent_name = if @full_name =~ /#/ then
+ $`
+ else
+ name = @full_name.split('::')
+ name.pop
+ name.join '::'
+ end
+
+ array[8].each do |old_name, new_name, comment|
+ add_alias RDoc::Alias.new(nil, old_name, new_name, comment)
+ end
+ end
+
+ ##
# Method name
def name
return @name if @name
- @name = @call_seq[/^.*?\.(\w+)/, 1] || @call_seq
+ @name = @call_seq[/^.*?\.(\w+)/, 1] || @call_seq if @call_seq
end
##
# Pretty parameter list for this method
@@ -160,10 +220,17 @@
params
end
##
+ # Name of our parent with special handling for un-marshaled methods
+
+ def parent_name
+ @parent_name || super
+ end
+
+ ##
# Path to this method
def path
"#{@parent.path}##{@aref}"
end
@@ -171,9 +238,34 @@
##
# Method name with class/instance indicator
def pretty_name
"#{singleton ? '::' : '#'}#{@name}"
+ end
+
+ def pretty_print q # :nodoc:
+ alias_for = @is_alias_for ? "alias for #{@is_alias_for.name}" : nil
+
+ q.group 2, "[#{self.class.name} #{full_name} #{visibility}", "]" do
+ if alias_for then
+ q.breakable
+ q.text alias_for
+ end
+
+ if text then
+ q.breakable
+ q.text "text:"
+ q.breakable
+ q.pp @text
+ end
+
+ unless comment.empty? then
+ q.breakable
+ q.text "comment:"
+ q.breakable
+ q.pp @comment
+ end
+ end
end
def to_s # :nodoc:
"#{self.class.name}: #{full_name} (#{@text})\n#{@comment}"
end