Included Modules

RDoc::AnyMethod

AnyMethod is the base class for objects representing methods

Attributes

name[W]

Method name

visibility[RW]

public, protected, private

block_params[RW]

Parameters yielded by the called block

dont_rename_initialize[RW]

Don’t rename #initialize to ::new

singleton[RW]

Is this a singleton method?

text[R]

Source file token stream

aliases[R]

Array of other names for this method

is_alias_for[RW]

The method we’re aliasing

params[RW]

Parameters for this method

call_seq[RW]

Different ways to call this method

Public Class Methods

new(text, name) click to toggle source
    # File lib/rdoc/any_method.rb, line 65
65:   def initialize(text, name)
66:     super()
67: 
68:     @text = text
69:     @name = name
70: 
71:     @aliases                = []
72:     @block_params           = nil
73:     @call_seq               = nil
74:     @dont_rename_initialize = false
75:     @is_alias_for           = nil
76:     @params                 = nil
77:     @parent_name            = nil
78:     @singleton              = nil
79:     @token_stream           = nil
80:     @visibility             = :public
81:   end

Public Instance Methods

<=>(other) click to toggle source

Order by singleton then name

    # File lib/rdoc/any_method.rb, line 86
86:   def <=>(other)
87:     [@singleton ? 0 : 1, @name] <=> [other.singleton ? 0 : 1, other.name]
88:   end
add_alias(method) click to toggle source

Adds method as an alias for this method

    # File lib/rdoc/any_method.rb, line 93
93:   def add_alias(method)
94:     @aliases << method
95:   end
add_line_numbers(src) click to toggle source

Prepend src with line numbers. Relies on the first line of a source code listing having:

   # File xxxxx, line dddd
    # File lib/rdoc/generator/markup.rb, line 68
68:   def add_line_numbers(src)
69:     if src =~ /\A.*, line (\d+)/ then
70:       first = $1.to_i - 1
71:       last  = first + src.count("\n")
72:       size = last.to_s.length
73: 
74:       line = first
75:       src.gsub!(/^/) do
76:         res = if line == first then
77:                 " " * (size + 2)
78:               else
79:                 "%2$*1$d: " % [size, line]
80:               end
81: 
82:         line += 1
83:         res
84:       end
85:     end
86:   end
aref() click to toggle source

HTML fragment reference for this method

     # File lib/rdoc/any_method.rb, line 100
100:   def aref
101:     type = singleton ? 'c' : 'i'
102: 
103:     "method-#{type}-#{CGI.escape name}"
104:   end
arglists() click to toggle source

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.

     # File lib/rdoc/any_method.rb, line 111
111:   def arglists
112:     if @call_seq then
113:       @call_seq
114:     elsif @params then
115:       "#{name}#{param_seq}"
116:     end
117:   end
full_name() click to toggle source

Full method name including namespace

     # File lib/rdoc/any_method.rb, line 139
139:   def full_name
140:     @full_name ||= "#{@parent ? @parent.full_name : '(unknown)'}#{pretty_name}"
141:   end
html_name() click to toggle source

HTML id-friendly method name

     # File lib/rdoc/any_method.rb, line 122
122:   def html_name
123:     @name.gsub(/[^a-z]+/, '-')
124:   end
markup_code() click to toggle source

Turns the method’s token stream into HTML

     # File lib/rdoc/generator/markup.rb, line 91
 91:   def markup_code
 92:     return '' unless @token_stream
 93: 
 94:     src = ""
 95: 
 96:     @token_stream.each do |t|
 97:       next unless t
 98:       #        style = STYLE_MAP[t.class]
 99:       style = case t
100:               when RDoc::RubyToken::TkCONSTANT then "ruby-constant"
101:               when RDoc::RubyToken::TkKW       then "ruby-keyword kw"
102:               when RDoc::RubyToken::TkIVAR     then "ruby-ivar"
103:               when RDoc::RubyToken::TkOp       then "ruby-operator"
104:               when RDoc::RubyToken::TkId       then "ruby-identifier"
105:               when RDoc::RubyToken::TkNode     then "ruby-node"
106:               when RDoc::RubyToken::TkCOMMENT  then "ruby-comment cmt"
107:               when RDoc::RubyToken::TkREGEXP   then "ruby-regexp re"
108:               when RDoc::RubyToken::TkSTRING   then "ruby-value str"
109:               when RDoc::RubyToken::TkVal      then "ruby-value"
110:               else
111:                 nil
112:               end
113: 
114:       text = CGI.escapeHTML t.text
115: 
116:       if style
117:         src << "<span class=\"#{style}\">#{text}</span>"
118:       else
119:         src << text
120:       end
121:     end
122: 
123:     add_line_numbers src
124: 
125:     src
126:   end
marshal_dump() click to toggle source

Dumps this AnyMethod for use by ri. See also marshal_load

     # File lib/rdoc/any_method.rb, line 146
146:   def marshal_dump
147:     aliases = @aliases.map do |a|
148:       [a.full_name, parse(a.comment)]
149:     end
150: 
151:     [ MARSHAL_VERSION,
152:       @name,
153:       full_name,
154:       @singleton,
155:       @visibility,
156:       parse(@comment),
157:       @call_seq,
158:       @block_params,
159:       aliases,
160:       @params,
161:     ]
162:   end
marshal_load(array) click to toggle source

Loads this AnyMethod from array. For a loaded AnyMethod the following methods will return cached values:

     # File lib/rdoc/any_method.rb, line 171
171:   def marshal_load(array)
172:     @dont_rename_initialize = nil
173:     @is_alias_for           = nil
174:     @token_stream           = nil
175:     @aliases                = []
176: 
177:     @name         = array[1]
178:     @full_name    = array[2]
179:     @singleton    = array[3]
180:     @visibility   = array[4]
181:     @comment      = array[5]
182:     @call_seq     = array[6]
183:     @block_params = array[7]
184:     @params       = array[9]
185: 
186:     @parent_name = if @full_name =~ /#/ then
187:                      $`
188:                    else
189:                      name = @full_name.split('::')
190:                      name.pop
191:                      name.join '::'
192:                    end
193: 
194:     array[8].each do |new_name, comment|
195:       add_alias RDoc::Alias.new(nil, @name, new_name, comment)
196:     end
197:   end
name() click to toggle source

Method name

     # File lib/rdoc/any_method.rb, line 202
202:   def name
203:     return @name if @name
204: 
205:     @name = @call_seq[/^.*?\.(\w+)/, 1] || @call_seq if @call_seq
206:   end
param_seq() click to toggle source

Pretty parameter list for this method

     # File lib/rdoc/any_method.rb, line 211
211:   def param_seq
212:     params = @params.gsub(/\s*\#.*/, '')
213:     params = params.tr("\n", " ").squeeze(" ")
214:     params = "(#{params})" unless params[0] == ((
215: 
216:     if @block_params then
217:       # If this method has explicit block parameters, remove any explicit
218:       # &block
219:       params.sub!(/,?\s*&\w+/, '')
220: 
221:       block = @block_params.gsub(/\s*\#.*/, '')
222:       block = block.tr("\n", " ").squeeze(" ")
223:       if block[0] == ((
224:         block.sub!(/^\(/, '').sub!(/\)/, '')
225:       end
226:       params << " { |#{block}| ... }"
227:     end
228: 
229:     params
230:   end
parent_name() click to toggle source

Name of our parent with special handling for un-marshaled methods

     # File lib/rdoc/any_method.rb, line 235
235:   def parent_name
236:     @parent_name || super
237:   end
path() click to toggle source

Path to this method

     # File lib/rdoc/any_method.rb, line 242
242:   def path
243:     "#{@parent.path}##{aref}"
244:   end
pretty_name() click to toggle source

Method name with class/instance indicator

     # File lib/rdoc/any_method.rb, line 249
249:   def pretty_name
250:     "#{singleton ? '::' : '#'}#{@name}"
251:   end
type() click to toggle source

Type of method (class or instance)

     # File lib/rdoc/any_method.rb, line 285
285:   def type
286:     singleton ? 'class' : 'instance'
287:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.