Method: RDoc::Parser::Ruby#get_method_container

Defined in:
lib/rdoc/parser/ruby.rb

#get_method_container(container, name_t) ⇒ Object

Retrieves the method container for a singleton method.



560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/rdoc/parser/ruby.rb', line 560

def get_method_container container, name_t # :nodoc:
  prev_container = container
  container = container.find_module_named(name_t[:text])

  unless container then
    constant = prev_container.constants.find do |const|
      const.name == name_t[:text]
    end

    if constant then
      parse_method_dummy prev_container
      return
    end
  end

  unless container then
    # TODO seems broken, should starting at Object in @store
    obj = name_t[:text].split("::").inject(Object) do |state, item|
      state.const_get(item)
    end rescue nil

    type = obj.class == Class ? RDoc::NormalClass : RDoc::NormalModule

    unless [Class, Module].include?(obj.class) then
      warn("Couldn't find #{name_t[:text]}. Assuming it's a module")
    end

    if type == RDoc::NormalClass then
      sclass = obj.superclass ? obj.superclass.name : nil
      container = prev_container.add_class type, name_t[:text], sclass
    else
      container = prev_container.add_module type, name_t[:text]
    end

    record_location container
  end

  container
end