AnyMethod is the base class for objects representing methods
# 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
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
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
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
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
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 id-friendly method name
# File lib/rdoc/any_method.rb, line 122
122: def html_name
123: @name.gsub(/[^a-z]+/, '-')
124: end
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
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
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
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
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
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 to this method
# File lib/rdoc/any_method.rb, line 242
242: def path
243: "#{@parent.path}##{aref}"
244: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.