Class: RDoc::AnyMethod
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
MethodAttr ,
CodeObject
|
|
Instance Chain:
|
|
Inherits: |
RDoc::MethodAttr
|
Defined in: | lib/rdoc/any_method.rb |
Overview
AnyMethod
is the base class for objects representing methods
Constant Summary
-
MARSHAL_VERSION =
Internal use only
- 2
-
RDoc 4 Added calls_super Added parent name and class Added section title
- 3
-
RDoc 4.1 Added is_alias_for
3
Text
- Included
Class Method Summary
-
.new(text, name) ⇒ AnyMethod
constructor
Creates a new
AnyMethod
with a token streamtext
and #name
MethodAttr
- Inherited
.new | Creates a new |
CodeObject
- Inherited
.new | Creates a new |
Instance Attribute Summary
-
#c_function
rw
The C function that implements this method (if it was defined in a C file).
-
#call_seq
rw
Different ways to call this method.
-
#call_seq=(call_seq)
rw
Sets the different ways you can call this method.
-
#calls_super
rw
If true this method uses
super
to call a superclass version. -
#dont_rename_initialize
rw
Don’t rename #initialize to ::new.
-
#params
rw
Parameters for this method.
-
#section_title
rw
The section title of the method (if defined in a C file via
:category:
). -
#store=(store)
writeonly
Sets the store for this method and its referenced code objects.
MethodAttr
- Inherited
#aliases | Array of other names for this method/attribute. |
#arglists | The call_seq or the param_seq with method name, if there is no call_seq. |
#block_params | Parameters yielded by the called block. |
#block_params= | Attempts to sanitize the content passed by the Ruby parser: remove outer parentheses, etc. |
#call_seq | Different ways to call this method. |
#documented? | A method/attribute is documented if any of the following is true: - it was marked with :nodoc:; - it has a comment; - it is an alias for a documented method; - it has a |
#is_alias_for | The method/attribute we’re aliasing. |
#name | Name of this method/attribute. |
#param_seq | Pretty parameter list for this method. |
#params | Parameters for this method. |
#singleton | Is this a singleton method/attribute? |
#store= | Sets the store for this class or module and its contained code objects. |
#text | Source file token stream. |
#visibility | public, protected, private. |
CodeObject
- Inherited
#comment | Our comment. |
#comment= | Replaces our comment with |
#display? | Should this |
#document_children | Do we document our children? |
#document_children= | Enables or disables documentation of this CodeObject’s children unless it has been turned off by :enddoc: |
#document_self | Do we document ourselves? |
#document_self= | Enables or disables documentation of this |
#documented? | Does this object have a comment with content or is |
#done_documenting | Are we done documenting (ie, did we come across a :enddoc:)? |
#done_documenting= | Turns documentation on/off, and turns on/off |
#file | Which file this code object was defined in. |
#force_documentation | Force documentation of this |
#force_documentation= | Force the documentation of this object unless documentation has been turned off by :enddoc: |
#full_name= | Sets the full_name overriding any computed full name. |
#ignored? | Has this class been ignored? |
#line | Line in |
#metadata | Hash of arbitrary metadata for this |
#parent | Our parent |
#parent= | Sets the parent |
#received_nodoc | Did we ever receive a |
#section | The section this |
#section= | Set the section this |
#store | The |
#store= | Sets the |
#suppressed? | Has this class been suppressed? |
#viewer | We are the model of the code, but we know that at some point we will be worked on by viewers. |
Text
- Included
Instance Method Summary
-
#add_alias(an_alias, context = nil)
Adds
an_alias
as an alias for this method incontext
. -
#aref_prefix
Prefix for
aref
is ‘method’. -
#arglists
The call_seq or the param_seq with method name, if there is no call_seq.
-
#marshal_dump
Dumps this
AnyMethod
for use by ri. -
#marshal_load(array)
Loads this
AnyMethod
fromarray
. -
#name
Method name.
-
#param_list
A list of this method’s method and yield parameters.
-
#param_seq
Pretty parameter list for this method.
-
#superclass_method
For methods that
super
, find the superclass method that would be called. -
#_call_seq
protected
call_seq without deduplication and alias lookup.
-
#deduplicate_call_seq(call_seq)
private
call_seq with alias examples information removed, if this method is an alias method.
-
#is_alias_for
Internal use only
Loads is_alias_for from the internal name.
TokenStream
- Included
#add_token | Adds one |
#add_tokens | Adds |
#collect_tokens | Starts collecting tokens. |
#pop_token | Remove the last token from the collected tokens. |
#start_collecting_tokens | |
#token_stream | Current token stream. |
#tokens_to_s | Returns a string representation of the token stream. |
MethodAttr
- Inherited
#<=> | Order by |
#add_alias | Abstract method. |
#add_line_numbers | Prepend |
#aref | HTML fragment reference for this method. |
#aref_prefix | Prefix for |
#full_name | Full method/attribute name including namespace. |
#html_name | HTML id-friendly method/attribute name. |
#markup_code | Turns the method’s token stream into HTML. |
#name_prefix | ‘::’ for a class method/attribute, ‘#’ for an instance method. |
#output_name | Name for output to HTML. |
#parent_name | Name of our parent with special handling for un-marshaled methods. |
#path | Path to this method for use with HTML generator output. |
#pretty_name | Method/attribute name with class/instance indicator. |
#search_record | Used by |
#see | A method/attribute to look at, in particular if this method/attribute has no documentation. |
#type | Type of method/attribute (class or instance). |
#==, #find_method_or_attribute, #find_see, | |
#initialize_copy | Resets cached data for the object so it can be rebuilt by accessor methods. |
#initialize_visibility, #inspect, #pretty_print, #to_s |
CodeObject
- Inherited
#each_parent | Yields each parent of this |
#file_name | File name where this |
#ignore | Use this to ignore a |
#options | The options instance from the store this |
#parent_file_name | File name of our parent. |
#parent_name | Name of our parent. |
#record_location | Records the |
#start_doc | Enable capture of documentation unless documentation has been turned off by :enddoc: |
#stop_doc | Disable capture of documentation. |
#suppress | Use this to suppress a |
#initialize_visibility | Initializes state for visibility of this |
Generator::Markup
- Included
#aref_to | Generates a relative URL from this object’s path to |
#as_href | Generates a relative URL from |
#cvs_url | Build a webcvs URL starting for the given |
#description | Handy wrapper for marking up this object’s comment. |
#formatter | Creates an |
Text
- Included
#expand_tabs | Expands tab characters in |
#flush_left | Flush |
#markup | Convert a string in markup format into HTML. |
#normalize_comment | Strips hashes, expands tabs then flushes |
#parse | Normalizes |
#snippet | The first |
#strip_hashes | Strips leading # characters from |
#strip_newlines | Strips leading and trailing n characters from |
#strip_stars | Strips /* */ style comments. |
#to_html | Converts ampersand, dashes, ellipsis, quotes, copyright and registered trademark symbols in |
#wrap | Wraps |
Constructor Details
.new(text, name) ⇒ AnyMethod
Creates a new AnyMethod
with a token stream text
and #name
# File 'lib/rdoc/any_method.rb', line 46
def initialize text, name super @c_function = nil @dont_rename_initialize = false @token_stream = nil @calls_super = false @superclass_method = nil end
Instance Attribute Details
#c_function (rw)
The C function that implements this method (if it was defined in a C file)
# File 'lib/rdoc/any_method.rb', line 27
attr_accessor :c_function
#call_seq (rw)
Different ways to call this method
# File 'lib/rdoc/any_method.rb', line 96
def call_seq unless call_seq = _call_seq call_seq = is_alias_for._call_seq if is_alias_for end return unless call_seq deduplicate_call_seq(call_seq) end
#call_seq=(call_seq) (rw)
Sets the different ways you can call this method. If an empty #call_seq is given nil is assumed.
See also #param_seq
#calls_super (rw)
If true this method uses super
to call a superclass version
# File 'lib/rdoc/any_method.rb', line 39
attr_accessor :calls_super
#dont_rename_initialize (rw)
Don’t rename #initialize to ::new
# File 'lib/rdoc/any_method.rb', line 22
attr_accessor :dont_rename_initialize
#params (rw)
Parameters for this method
# File 'lib/rdoc/any_method.rb', line 34
attr_accessor :params
#section_title (rw)
The section title of the method (if defined in a C file via :category:
)
# File 'lib/rdoc/any_method.rb', line 30
attr_accessor :section_title
#store=(store) (writeonly)
Sets the store for this method and its referenced code objects.
# File 'lib/rdoc/any_method.rb', line 302
def store= store super @file = @store.add_file @file.full_name if @file end
Instance Method Details
#_call_seq (protected)
call_seq without deduplication and alias lookup.
# File 'lib/rdoc/any_method.rb', line 330
def _call_seq @call_seq if defined?(@call_seq) && @call_seq end
#add_alias(an_alias, context = nil)
Adds an_alias
as an alias for this method in context
.
# File 'lib/rdoc/any_method.rb', line 59
def add_alias an_alias, context = nil method = self.class.new an_alias.text, an_alias.new_name method.record_location an_alias.file method.singleton = self.singleton method.params = self.params method.visibility = self.visibility method.comment = an_alias.comment method.is_alias_for = self @aliases << method context.add_method method if context method end
#aref_prefix
Prefix for aref
is ‘method’.
# File 'lib/rdoc/any_method.rb', line 76
def aref_prefix 'method' end
#arglists
The call_seq or the param_seq with method name, if there is no call_seq.
Use this for displaying a method’s argument lists.
#deduplicate_call_seq(call_seq) (private)
call_seq with alias examples information removed, if this method is an alias method.
# File 'lib/rdoc/any_method.rb', line 340
def deduplicate_call_seq(call_seq) return call_seq unless is_alias_for || !aliases.empty? method_name = self.name method_name = method_name[0, 1] if method_name =~ /\A\[/ entries = call_seq.split "\n" ignore = aliases.map(&:name) if is_alias_for ignore << is_alias_for.name ignore.concat is_alias_for.aliases.map(&:name) end ignore.map! { |n| n =~ /\A\[/ ? n[0, 1] : n} ignore.delete(method_name) ignore = Regexp.union(ignore) matching = entries.reject do |entry| entry =~ /^\w*\.?#{ignore}/ or entry =~ /\s#{ignore}\s/ end matching.empty? ? nil : matching.join("\n") end
#is_alias_for
Loads is_alias_for from the internal name. Returns nil if the alias cannot be found.
# File 'lib/rdoc/any_method.rb', line 122
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
#marshal_dump
Dumps this AnyMethod
for use by ri. See also #marshal_load
# File 'lib/rdoc/any_method.rb', line 140
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, parse(@comment), @call_seq, @block_params, aliases, @params, @file.relative_name, @calls_super, @parent.name, @parent.class, @section.title, is_alias_for, ] end
#marshal_load(array)
Loads this AnyMethod
from array
. For a loaded AnyMethod
the following methods will return cached values:
-
#full_name
-
#parent_name
# File 'lib/rdoc/any_method.rb', line 177
def marshal_load array initialize_visibility @dont_rename_initialize = nil @token_stream = nil @aliases = [] @parent = nil @parent_name = nil @parent_class = nil @section = nil @file = nil version = array[0] @name = array[1] @full_name = array[2] @singleton = array[3] @visibility = array[4] @comment = array[5] @call_seq = array[6] @block_params = array[7] # 8 handled below @params = array[9] # 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 @parent_name ||= if @full_name =~ /#/ then $` else name = @full_name.split('::') name.pop name.join '::' end @file = RDoc::TopLevel.new array[10] if version > 0 end
#name
Method name
If the method has no assigned name, it extracts it from #call_seq.
# File 'lib/rdoc/any_method.rb', line 226
def name return @name if @name @name = @call_seq[/^.*?\.(\w+)/, 1] || @call_seq[/^.*?(\w+)/, 1] || @call_seq if @call_seq end
#param_list
A list of this method’s method and yield parameters. call-seq
params are preferred over parsed method and block params.
# File 'lib/rdoc/any_method.rb', line 239
def param_list if @call_seq then params = @call_seq.split("\n").last params = params.sub(/.*?\((.*)\)/, '\1') params = params.sub(/(\{|do)\s*\|([^|]*)\|.*/, ',\2') elsif @params then params = @params.sub(/\((.*)\)/, '\1') params << ",#{@block_params}" if @block_params elsif @block_params then params = @block_params else return [] end if @block_params then # If this method has explicit block parameters, remove any explicit # &block params = params.sub(/,?\s*&\w+/, '') else params = params.sub(/\&(\w+)/, '\1') end params = params.gsub(/\s+/, '').split(',').reject(&:empty?) params.map { |param| param.sub(/=.*/, '') } end
#param_seq
Pretty parameter list for this method. If the method’s parameters were given by call-seq
it is preferred over the parsed values.
# File 'lib/rdoc/any_method.rb', line 271
def param_seq if @call_seq then params = @call_seq.split("\n").last params = params.sub(/[^( ]+/, '') params = params.sub(/(\|[^|]+\|)\s*\.\.\.\s*(end|\})/, '\1 \2') elsif @params then params = @params.gsub(/\s*\#.*/, '') params = params.tr_s("\n ", " ") params = "(#{params})" unless params[0] == ?( else params = '' end if @block_params then # If this method has explicit block parameters, remove any explicit # &block params = params.sub(/,?\s*&\w+/, '') block = @block_params.tr_s("\n ", " ") if block[0] == ?( block = block.sub(/^\(/, '').sub(/\)/, '') end params << " { |#{block}| ... }" end params end
#superclass_method
For methods that super
, find the superclass method that would be called.
# File 'lib/rdoc/any_method.rb', line 311
def superclass_method return unless @calls_super return @superclass_method if @superclass_method parent.each_ancestor do |ancestor| if method = ancestor.method_list.find { |m| m.name == @name } then @superclass_method = method break end end @superclass_method end