class RDoc::MethodAttr

def <=>(other)

def <=>(other)
  return unless other.respond_to?(:singleton) &&
                other.respond_to?(:name)
  [@singleton      ? 0 : 1, name_ord_range,       name] <=>
  [other.singleton ? 0 : 1, other.name_ord_range, other.name]
end

def == other # :nodoc:

:nodoc:
def == other # :nodoc:
  equal?(other) or self.class == other.class and full_name == other.full_name
end

def add_alias(an_alias, context)

def add_alias(an_alias, context)
  raise NotImplementedError
end

def add_line_numbers(src)

def add_line_numbers(src)
  return unless src.sub!(/\A(.*)(, line (\d+))/, '\1')
  first = $3.to_i - 1
  last  = first + src.count("\n")
  size = last.to_s.length
  line = first
  src.gsub!(/^/) do
    res = if line == first then
            " " * (size + 1)
          else
            "<span class=\"line-num\">%2$*1$d</span> " % [size, line]
          end
    line += 1
    res
  end
end

def aref

def aref
  type = singleton ? 'c' : 'i'
  # % characters are not allowed in html names => dash instead
  "#{aref_prefix}-#{type}-#{html_name}"
end

def aref_prefix

def aref_prefix
  raise NotImplementedError
end

def block_params=(value)

def block_params=(value)
  # 'yield.to_s' or 'assert yield, msg'
  return @block_params = '' if value =~ /^[\.,]/
  # remove trailing 'if/unless ...'
  return @block_params = '' if value =~ /^(if|unless)\s/
  value = $1.strip if value =~ /^(.+)\s(if|unless)\s/
  # outer parentheses
  value = $1 if value =~ /^\s*\((.*)\)\s*$/
  value = value.strip
  # proc/lambda
  return @block_params = $1 if value =~ /^(proc|lambda)(\s*\{|\sdo)/
  # surrounding +...+ or [...]
  value = $1.strip if value =~ /^\+(.*)\+$/
  value = $1.strip if value =~ /^\[(.*)\]$/
  return @block_params = '' if value.empty?
  # global variable
  return @block_params = 'str' if value =~ /^\$[&0-9]$/
  # wipe out array/hash indices
  value.gsub!(/(\w)\[[^\[]+\]/, '\1')
  # remove @ from class/instance variables
  value.gsub!(/@@?([a-z0-9_]+)/, '\1')
  # method calls => method name
  value.gsub!(/([A-Z:a-z0-9_]+)\.([a-z0-9_]+)(\s*\(\s*[a-z0-9_.,\s]*\s*\)\s*)?/) do
    case $2
    when 'to_s'      then $1
    when 'const_get' then 'const'
    when 'new' then
      $1.split('::').last.  # ClassName => class_name
        gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
        gsub(/([a-z\d])([A-Z])/, '\1_\2').
        downcase
    else
      $2
    end
  end
  # class prefixes
  value.gsub!(/[A-Za-z0-9_:]+::/, '')
  # simple expressions
  value = $1 if value =~ /^([a-z0-9_]+)\s*[-*+\/]/
  @block_params = value.strip
end

def documented?

def documented?
  super or
    (is_alias_for and is_alias_for.documented?) or
    (see and see.documented?)
end

def find_method_or_attribute name # :nodoc:

:nodoc:
def find_method_or_attribute name # :nodoc:
  return nil unless parent.respond_to? :ancestors
  searched = parent.ancestors
  kernel = @store.modules_hash['Kernel']
  searched << kernel if kernel &&
    parent != kernel && !searched.include?(kernel)
  searched.each do |ancestor|
    next if String === ancestor
    next if parent == ancestor
    other = ancestor.find_method_named('#' + name) ||
            ancestor.find_attribute_named(name)
    return other if other
  end
  nil
end

def find_see # :nodoc:

:nodoc:
def find_see # :nodoc:
  return nil if singleton || is_alias_for
  # look for the method
  other = find_method_or_attribute name
  return other if other
  # if it is a setter, look for a getter
  return nil unless name =~ /[a-z_]=$/i   # avoid == or ===
  return find_method_or_attribute name[0..-2]
end

def full_name

def full_name
  @full_name ||= "#{parent_name}#{pretty_name}"
end

def html_name

def html_name
  require 'cgi/util'
  CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
end

def initialize text, name

def initialize text, name
  super()
  @text = text
  @name = name
  @aliases      = []
  @is_alias_for = nil
  @parent_name  = nil
  @singleton    = nil
  @visibility   = :public
  @see = false
  @arglists     = nil
  @block_params = nil
  @call_seq     = nil
  @param_seq    = nil
  @params       = nil
end

def initialize_copy other # :nodoc:

:nodoc:
def initialize_copy other # :nodoc:
  @full_name = nil
end

def initialize_visibility # :nodoc:

:nodoc:
def initialize_visibility # :nodoc:
  super
  @see = nil
end

def inspect # :nodoc:

:nodoc:
def inspect # :nodoc:
  alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
  visibility = self.visibility
  visibility = "forced #{visibility}" if force_documentation
  "#<%s:0x%x %s (%s)%s>" % [
    self.class, object_id,
    full_name,
    visibility,
    alias_for,
  ]
end

def markup_code

def markup_code
  return '' unless @token_stream
  src = RDoc::TokenStream.to_html @token_stream
  # dedent the source
  indent = src.length
  lines = src.lines.to_a
  lines.shift if src =~ /\A.*#\ *File/i # remove '# File' comment
  lines.each do |line|
    if line =~ /^ *(?=\S)/
      n = $~.end(0)
      indent = n if n < indent
      break if n == 0
    end
  end
  src.gsub!(/^#{' ' * indent}/, '') if indent > 0
  add_line_numbers(src) if options.line_numbers
  src
end

def name_ord_range # :nodoc:

:nodoc:
def name_ord_range # :nodoc:
  case name.ord
  when 0..64 # anything below "A"
    1
  when 91..96 # the symbols between "Z" and "a"
    2
  when 123..126 # 7-bit symbols above "z": "{", "|", "}", "~"
    3
  else # everythig else can be sorted as normal
    4
  end
end

def name_prefix

def name_prefix
  @singleton ? '::' : '#'
end

def output_name context

def output_name context
  return "#{name_prefix}#{@name}" if context == parent
  "#{parent_name}#{@singleton ? '.' : '#'}#{@name}"
end

def parent_name

def parent_name
  @parent_name || super
end

def path

def path
  "#{@parent.path}##{aref}"
end

def pretty_name

def pretty_name
  "#{name_prefix}#{@name}"
end

def pretty_print q # :nodoc:

:nodoc:
def pretty_print q # :nodoc:
  alias_for =
    if @is_alias_for.respond_to? :name then
      "alias for #{@is_alias_for.name}"
    elsif Array === @is_alias_for then
      "alias for #{@is_alias_for.last}"
    end
  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 search_record

def search_record
  [
    @name,
    full_name,
    @name,
    @parent.full_name,
    path,
    params,
    snippet(@comment),
  ]
end

def see

def see
  @see = find_see if @see == false
  @see
end

def store= store

def store= store
  super
  @file = @store.add_file @file.full_name if @file
end

def to_s # :nodoc:

:nodoc:
def to_s # :nodoc:
  if @is_alias_for
    "#{self.class.name}: #{full_name} -> #{is_alias_for}"
  else
    "#{self.class.name}: #{full_name}"
  end
end

def type

def type
  singleton ? 'class' : 'instance'
end