Class: RDoc::AnyMethod

Inherits:
CodeObject show all
Includes:
TokenStream
Defined in:
lib/rdoc/code_objects.rb

Overview

AnyMethod is the base class for objects representing methods

Instance Attribute Summary collapse

Attributes inherited from CodeObject

#comment, #document_children, #document_self, #done_documenting, #force_documentation, #parent, #section, #viewer

Instance Method Summary collapse

Methods included from TokenStream

#add_token, #add_tokens, #pop_token, #start_collecting_tokens, #token_stream

Methods inherited from CodeObject

attr_overridable, #remove_classes_and_modules, #remove_methods_etc, #start_doc, #stop_doc

Constructor Details

#initialize(text, name) ⇒ AnyMethod

Returns a new instance of AnyMethod.



636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/rdoc/code_objects.rb', line 636

def initialize(text, name)
  super()
  @text = text
  @name = name
  @token_stream  = nil
  @visibility    = :public
  @dont_rename_initialize = false
  @block_params  = nil
  @aliases       = []
  @is_alias_for  = nil
  @comment = ""
  @call_seq = nil
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases



626
627
628
# File 'lib/rdoc/code_objects.rb', line 626

def aliases
  @aliases
end

#block_paramsObject

Returns the value of attribute block_params



623
624
625
# File 'lib/rdoc/code_objects.rb', line 623

def block_params
  @block_params
end

#call_seqObject

Returns the value of attribute call_seq



631
632
633
# File 'lib/rdoc/code_objects.rb', line 631

def call_seq
  @call_seq
end

#dont_rename_initializeObject

Returns the value of attribute dont_rename_initialize



624
625
626
# File 'lib/rdoc/code_objects.rb', line 624

def dont_rename_initialize
  @dont_rename_initialize
end

#is_alias_forObject

list of other names for this method or a method we're aliasing



627
628
629
# File 'lib/rdoc/code_objects.rb', line 627

def is_alias_for
  @is_alias_for
end

#nameObject

Returns the value of attribute name



621
622
623
# File 'lib/rdoc/code_objects.rb', line 621

def name
  @name
end

#singletonObject

Returns the value of attribute singleton



625
626
627
# File 'lib/rdoc/code_objects.rb', line 625

def singleton
  @singleton
end

#visibilityObject

Returns the value of attribute visibility



622
623
624
# File 'lib/rdoc/code_objects.rb', line 622

def visibility
  @visibility
end

Instance Method Details

#<=>(other) ⇒ Object



650
651
652
# File 'lib/rdoc/code_objects.rb', line 650

def <=>(other)
  @name <=> other.name
end

#add_alias(method) ⇒ Object



682
683
684
# File 'lib/rdoc/code_objects.rb', line 682

def add_alias(method)
  @aliases << method
end

#param_seqObject



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'lib/rdoc/code_objects.rb', line 660

def param_seq
  p = params.gsub(/\s*\#.*/, '')
  p = p.tr("\n", " ").squeeze(" ")
  p = "(" + p + ")" unless p[0] == ?(

  if (block = block_params)
    # If this method has explicit block parameters, remove any
    # explicit &block
$stderr.puts p
    p.sub!(/,?\s*&\w+/)
$stderr.puts p

    block.gsub!(/\s*\#.*/, '')
    block = block.tr("\n", " ").squeeze(" ")
    if block[0] == ?(
      block.sub!(/^\(/, '').sub!(/\)/, '')
    end
    p << " {|#{block}| ...}"
  end
  p
end

#to_sObject



654
655
656
657
658
# File 'lib/rdoc/code_objects.rb', line 654

def to_s
  res = self.class.name + ": " + @name + " (" + @text + ")\n"
  res << @comment.to_s
  res
end