rdoc 7.2.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +4 -7
  3. data/LICENSE.rdoc +4 -0
  4. data/README.md +43 -2
  5. data/RI.md +75 -75
  6. data/doc/markup_reference/markdown.md +104 -3
  7. data/exe/rdoc +2 -2
  8. data/lib/rdoc/code_object/alias.rb +70 -74
  9. data/lib/rdoc/code_object/any_method.rb +305 -298
  10. data/lib/rdoc/code_object/attr.rb +150 -143
  11. data/lib/rdoc/code_object/class_module.rb +801 -765
  12. data/lib/rdoc/code_object/constant.rb +178 -150
  13. data/lib/rdoc/code_object/context/section.rb +133 -160
  14. data/lib/rdoc/code_object/context.rb +925 -952
  15. data/lib/rdoc/code_object/extend.rb +7 -5
  16. data/lib/rdoc/code_object/include.rb +7 -5
  17. data/lib/rdoc/code_object/method_attr.rb +325 -324
  18. data/lib/rdoc/code_object/mixin.rb +97 -95
  19. data/lib/rdoc/code_object/normal_class.rb +77 -78
  20. data/lib/rdoc/code_object/normal_module.rb +61 -59
  21. data/lib/rdoc/code_object/require.rb +23 -39
  22. data/lib/rdoc/code_object/single_class.rb +21 -19
  23. data/lib/rdoc/code_object/top_level.rb +212 -213
  24. data/lib/rdoc/code_object.rb +305 -305
  25. data/lib/rdoc/comment.rb +274 -337
  26. data/lib/rdoc/cross_reference.rb +194 -212
  27. data/lib/rdoc/encoding.rb +105 -103
  28. data/lib/rdoc/erb_partial.rb +13 -11
  29. data/lib/rdoc/erbio.rb +29 -27
  30. data/lib/rdoc/generator/aliki.rb +165 -140
  31. data/lib/rdoc/generator/darkfish.rb +647 -631
  32. data/lib/rdoc/generator/json_index.rb +233 -229
  33. data/lib/rdoc/generator/markup.rb +165 -122
  34. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  35. data/lib/rdoc/generator/pot/po.rb +52 -51
  36. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  37. data/lib/rdoc/generator/pot.rb +85 -81
  38. data/lib/rdoc/generator/ri.rb +23 -19
  39. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  40. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  41. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  42. data/lib/rdoc/generator/template/aliki/_head.rhtml +11 -11
  43. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  44. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  45. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  46. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  47. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +2 -2
  48. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  49. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  50. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  51. data/lib/rdoc/generator/template/aliki/class.rhtml +56 -46
  52. data/lib/rdoc/generator/template/aliki/css/rdoc.css +538 -283
  53. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  54. data/lib/rdoc/generator/template/aliki/js/aliki.js +80 -102
  55. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  57. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  58. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  59. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  60. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  61. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  62. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  63. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  64. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  65. data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
  66. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
  67. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  68. data/lib/rdoc/generator.rb +48 -46
  69. data/lib/rdoc/i18n/locale.rb +99 -95
  70. data/lib/rdoc/i18n/text.rb +109 -105
  71. data/lib/rdoc/i18n.rb +7 -5
  72. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  73. data/lib/rdoc/markdown.kpeg +30 -21
  74. data/lib/rdoc/markdown.rb +329 -151
  75. data/lib/rdoc/markup/block_quote.rb +12 -8
  76. data/lib/rdoc/markup/document.rb +127 -123
  77. data/lib/rdoc/markup/formatter.rb +215 -221
  78. data/lib/rdoc/markup/heading.rb +1 -4
  79. data/lib/rdoc/markup/include.rb +33 -29
  80. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  81. data/lib/rdoc/markup/inline_parser.rb +281 -277
  82. data/lib/rdoc/markup/list.rb +80 -88
  83. data/lib/rdoc/markup/list_item.rb +73 -85
  84. data/lib/rdoc/markup/paragraph.rb +23 -19
  85. data/lib/rdoc/markup/parser.rb +501 -497
  86. data/lib/rdoc/markup/pre_process.rb +284 -305
  87. data/lib/rdoc/markup/raw.rb +2 -2
  88. data/lib/rdoc/markup/rule.rb +16 -12
  89. data/lib/rdoc/markup/to_ansi.rb +143 -139
  90. data/lib/rdoc/markup/to_bs.rb +72 -68
  91. data/lib/rdoc/markup/to_html.rb +600 -493
  92. data/lib/rdoc/markup/to_html_crossref.rb +221 -191
  93. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  94. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  95. data/lib/rdoc/markup/to_label.rb +63 -59
  96. data/lib/rdoc/markup/to_markdown.rb +212 -208
  97. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  98. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  99. data/lib/rdoc/markup/to_test.rb +60 -56
  100. data/lib/rdoc/markup/to_tt_only.rb +83 -86
  101. data/lib/rdoc/markup/verbatim.rb +62 -58
  102. data/lib/rdoc/markup.rb +198 -196
  103. data/lib/rdoc/options.rb +1063 -1076
  104. data/lib/rdoc/parser/c.rb +1039 -1036
  105. data/lib/rdoc/parser/changelog.rb +319 -315
  106. data/lib/rdoc/parser/markdown.rb +17 -13
  107. data/lib/rdoc/parser/rbs.rb +279 -0
  108. data/lib/rdoc/parser/rd.rb +17 -13
  109. data/lib/rdoc/parser/ruby.rb +1231 -2222
  110. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  111. data/lib/rdoc/parser/simple.rb +31 -27
  112. data/lib/rdoc/parser/text.rb +12 -8
  113. data/lib/rdoc/parser.rb +230 -221
  114. data/lib/rdoc/rbs_helper.rb +186 -0
  115. data/lib/rdoc/rd/inline.rb +57 -53
  116. data/lib/rdoc/rd.rb +90 -88
  117. data/lib/rdoc/rdoc.rb +547 -366
  118. data/lib/rdoc/ri/driver.rb +1141 -1130
  119. data/lib/rdoc/ri/formatter.rb +7 -3
  120. data/lib/rdoc/ri/paths.rb +140 -136
  121. data/lib/rdoc/ri/servlet.rb +456 -0
  122. data/lib/rdoc/ri/store.rb +4 -2
  123. data/lib/rdoc/ri/task.rb +55 -51
  124. data/lib/rdoc/ri.rb +14 -11
  125. data/lib/rdoc/rubygems_hook.rb +194 -192
  126. data/lib/rdoc/server.rb +462 -0
  127. data/lib/rdoc/stats/normal.rb +46 -42
  128. data/lib/rdoc/stats/quiet.rb +39 -35
  129. data/lib/rdoc/stats/verbose.rb +35 -31
  130. data/lib/rdoc/stats.rb +363 -338
  131. data/lib/rdoc/store.rb +919 -725
  132. data/lib/rdoc/task.rb +260 -255
  133. data/lib/rdoc/text.rb +130 -245
  134. data/lib/rdoc/token_stream.rb +101 -115
  135. data/lib/rdoc/tom_doc.rb +203 -201
  136. data/lib/rdoc/version.rb +1 -1
  137. data/lib/rdoc.rb +35 -7
  138. data/lib/rubygems_plugin.rb +2 -11
  139. data/rdoc-logo.svg +43 -0
  140. data/rdoc.gemspec +6 -4
  141. metadata +36 -20
  142. data/lib/rdoc/code_object/anon_class.rb +0 -10
  143. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  144. data/lib/rdoc/code_object/meta_method.rb +0 -6
  145. data/lib/rdoc/markdown/literals.kpeg +0 -21
  146. data/lib/rdoc/markdown/literals.rb +0 -454
  147. data/lib/rdoc/parser/prism_ruby.rb +0 -1112
  148. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  149. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  150. data/lib/rdoc/servlet.rb +0 -452
@@ -1,423 +1,424 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Abstract class representing either a method or an attribute.
4
-
5
- class RDoc::MethodAttr < RDoc::CodeObject
6
-
7
- include Comparable
8
-
2
+ module RDoc
9
3
  ##
10
- # Name of this method/attribute.
4
+ # Abstract class representing either a method or an attribute.
11
5
 
12
- attr_accessor :name
6
+ class MethodAttr < CodeObject
13
7
 
14
- ##
15
- # public, protected, private
8
+ include Comparable
16
9
 
17
- attr_accessor :visibility
10
+ ##
11
+ # Name of this method/attribute.
18
12
 
19
- ##
20
- # Is this a singleton method/attribute?
13
+ attr_accessor :name
21
14
 
22
- attr_accessor :singleton
15
+ ##
16
+ # public, protected, private
23
17
 
24
- ##
25
- # Source file token stream
18
+ attr_accessor :visibility
26
19
 
27
- attr_reader :text
20
+ ##
21
+ # Is this a singleton method/attribute?
28
22
 
29
- ##
30
- # Array of other names for this method/attribute
23
+ attr_accessor :singleton
31
24
 
32
- attr_reader :aliases
25
+ ##
26
+ # Array of other names for this method/attribute
33
27
 
34
- ##
35
- # The method/attribute we're aliasing
28
+ attr_reader :aliases
36
29
 
37
- attr_accessor :is_alias_for
30
+ ##
31
+ # The method/attribute we're aliasing
38
32
 
39
- #--
40
- # The attributes below are for AnyMethod only.
41
- # They are left here for the time being to
42
- # allow ri to operate.
43
- # TODO modify ri to avoid calling these on attributes.
44
- #++
33
+ attr_accessor :is_alias_for
45
34
 
46
- ##
47
- # Parameters yielded by the called block
35
+ #--
36
+ # The attributes below are for AnyMethod only.
37
+ # They are left here for the time being to
38
+ # allow ri to operate.
39
+ # TODO modify ri to avoid calling these on attributes.
40
+ #++
48
41
 
49
- attr_reader :block_params
42
+ ##
43
+ # Parameters yielded by the called block
50
44
 
51
- ##
52
- # Parameters for this method
45
+ attr_reader :block_params
53
46
 
54
- attr_accessor :params
47
+ ##
48
+ # Parameters for this method
55
49
 
56
- ##
57
- # Different ways to call this method
50
+ attr_accessor :params
58
51
 
59
- attr_accessor :call_seq
52
+ ##
53
+ # Different ways to call this method
60
54
 
61
- ##
62
- # The call_seq or the param_seq with method name, if there is no call_seq.
55
+ attr_accessor :call_seq
63
56
 
64
- attr_reader :arglists
57
+ ##
58
+ # RBS type signature lines from inline annotations or loaded .rbs files.
59
+ # Each entry is one overload or type expression.
65
60
 
66
- ##
67
- # Creates a new MethodAttr from token stream +text+ and method or attribute
68
- # name +name+.
69
- #
70
- # Usually this is called by super from a subclass.
71
-
72
- def initialize(text, name, singleton: false)
73
- super()
74
-
75
- @text = text
76
- @name = name
77
-
78
- @aliases = []
79
- @is_alias_for = nil
80
- @parent_name = nil
81
- @singleton = singleton
82
- @visibility = :public
83
- @see = false
84
-
85
- @arglists = nil
86
- @block_params = nil
87
- @call_seq = nil
88
- @params = nil
89
- end
61
+ attr_accessor :type_signature_lines
90
62
 
91
- ##
92
- # Resets cached data for the object so it can be rebuilt by accessor methods
63
+ ##
64
+ # The call_seq or the param_seq with method name, if there is no call_seq.
93
65
 
94
- def initialize_copy(other) # :nodoc:
95
- @full_name = nil
96
- end
66
+ attr_reader :arglists
97
67
 
98
- def initialize_visibility # :nodoc:
99
- super
100
- @see = nil
101
- end
68
+ ##
69
+ # Creates a new MethodAttr with method or attribute
70
+ # name +name+.
71
+ #
72
+ # Usually this is called by super from a subclass.
102
73
 
103
- ##
104
- # Order by #singleton then #name
74
+ def initialize(name, singleton: false)
75
+ super()
105
76
 
106
- def <=>(other)
107
- return unless other.respond_to?(:singleton) &&
108
- other.respond_to?(:name)
77
+ @name = name
109
78
 
110
- [@singleton ? 0 : 1, name_ord_range, name] <=>
111
- [other.singleton ? 0 : 1, other.name_ord_range, other.name]
112
- end
79
+ @aliases = []
80
+ @is_alias_for = nil
81
+ @parent_name = nil
82
+ @singleton = singleton
83
+ @visibility = :public
84
+ @see = false
113
85
 
114
- def ==(other) # :nodoc:
115
- equal?(other) or self.class == other.class and full_name == other.full_name
116
- end
86
+ @arglists = nil
87
+ @block_params = nil
88
+ @call_seq = nil
89
+ @params = nil
90
+ @type_signature_lines = nil
91
+ end
117
92
 
118
- ##
119
- # A method/attribute is documented if any of the following is true:
120
- # - it was marked with :nodoc:;
121
- # - it has a comment;
122
- # - it is an alias for a documented method;
123
- # - it has a +#see+ method that is documented.
124
-
125
- def documented?
126
- super or
127
- (is_alias_for and is_alias_for.documented?) or
128
- (see and see.documented?)
129
- end
93
+ ##
94
+ # Resets cached data for the object so it can be rebuilt by accessor methods
130
95
 
131
- ##
132
- # A method/attribute to look at,
133
- # in particular if this method/attribute has no documentation.
134
- #
135
- # It can be a method/attribute of the superclass or of an included module,
136
- # including the Kernel module, which is always appended to the included
137
- # modules.
138
- #
139
- # Returns +nil+ if there is no such method/attribute.
140
- # The +#is_alias_for+ method/attribute, if any, is not included.
141
- #
142
- # Templates may generate a "see also ..." if this method/attribute
143
- # has documentation, and "see ..." if it does not.
144
-
145
- def see
146
- @see = find_see if @see == false
147
- @see
148
- end
96
+ def initialize_copy(other) # :nodoc:
97
+ @full_name = nil
98
+ end
149
99
 
150
- ##
151
- # Sets the store for this class or module and its contained code objects.
100
+ def initialize_visibility # :nodoc:
101
+ super
102
+ @see = nil
103
+ end
152
104
 
153
- def store=(store)
154
- super
105
+ ##
106
+ # Order by #singleton then #name
155
107
 
156
- @file = @store.add_file @file.full_name if @file
157
- end
108
+ def <=>(other)
109
+ return unless other.respond_to?(:singleton) &&
110
+ other.respond_to?(:name)
158
111
 
159
- def find_see # :nodoc:
160
- return nil if singleton || is_alias_for
112
+ [@singleton ? 0 : 1, name_ord_range, name] <=>
113
+ [other.singleton ? 0 : 1, other.name_ord_range, other.name]
114
+ end
161
115
 
162
- # look for the method
163
- other = find_method_or_attribute name
164
- return other if other
116
+ def ==(other) # :nodoc:
117
+ equal?(other) or self.class == other.class and full_name == other.full_name
118
+ end
165
119
 
166
- # if it is a setter, look for a getter
167
- return nil unless name =~ /[a-z_]=$/i # avoid == or ===
168
- return find_method_or_attribute name[0..-2]
169
- end
120
+ ##
121
+ # A method/attribute is documented if any of the following is true:
122
+ # - it was marked with :nodoc:;
123
+ # - it has a comment;
124
+ # - it is an alias for a documented method;
125
+ # - it has a +#see+ method that is documented.
126
+
127
+ def documented?
128
+ super or
129
+ (is_alias_for and is_alias_for.documented?) or
130
+ (see and see.documented?)
131
+ end
170
132
 
171
- def find_method_or_attribute(name) # :nodoc:
172
- return nil unless parent.respond_to? :ancestors
133
+ ##
134
+ # A method/attribute to look at,
135
+ # in particular if this method/attribute has no documentation.
136
+ #
137
+ # It can be a method/attribute of the superclass or of an included module,
138
+ # including the Kernel module, which is always appended to the included
139
+ # modules.
140
+ #
141
+ # Returns +nil+ if there is no such method/attribute.
142
+ # The +#is_alias_for+ method/attribute, if any, is not included.
143
+ #
144
+ # Templates may generate a "see also ..." if this method/attribute
145
+ # has documentation, and "see ..." if it does not.
146
+
147
+ def see
148
+ @see = find_see if @see == false
149
+ @see
150
+ end
173
151
 
174
- searched = parent.ancestors
175
- kernel = @store.modules_hash['Kernel']
152
+ ##
153
+ # Sets the store for this class or module and its contained code objects.
176
154
 
177
- searched << kernel if kernel &&
178
- parent != kernel && !searched.include?(kernel)
155
+ def store=(store)
156
+ super
179
157
 
180
- searched.each do |ancestor|
181
- next if String === ancestor
182
- next if parent == ancestor
158
+ @file = @store.add_file @file.full_name if @file
159
+ end
183
160
 
184
- other = ancestor.find_method_named('#' + name) ||
185
- ancestor.find_attribute_named(name)
161
+ def find_see # :nodoc:
162
+ return nil if singleton || is_alias_for
186
163
 
164
+ # look for the method
165
+ other = find_method_or_attribute name
187
166
  return other if other
167
+
168
+ # if it is a setter, look for a getter
169
+ return nil unless name =~ /[a-z_]=$/i # avoid == or ===
170
+ return find_method_or_attribute name[0..-2]
188
171
  end
189
172
 
190
- nil
191
- end
173
+ def find_method_or_attribute(name) # :nodoc:
174
+ return nil unless parent.respond_to? :ancestors
192
175
 
193
- ##
194
- # Abstract method. Contexts in their building phase call this
195
- # to register a new alias for this known method/attribute.
196
- #
197
- # - creates a new AnyMethod/Attribute named <tt>an_alias.new_name</tt>;
198
- # - adds +self+ as an alias for the new method or attribute
199
- # - adds the method or attribute to #aliases
200
- # - adds the method or attribute to +context+.
201
-
202
- def add_alias(an_alias, context)
203
- raise NotImplementedError
204
- end
176
+ searched = parent.ancestors
177
+ kernel = @store.modules_hash['Kernel']
205
178
 
206
- ##
207
- # HTML fragment reference for this method
179
+ searched << kernel if kernel &&
180
+ parent != kernel && !searched.include?(kernel)
208
181
 
209
- def aref
210
- type = singleton ? 'c' : 'i'
211
- # % characters are not allowed in html names => dash instead
212
- "#{aref_prefix}-#{type}-#{html_name}"
213
- end
182
+ searched.each do |ancestor|
183
+ next if String === ancestor
184
+ next if parent == ancestor
214
185
 
215
- ##
216
- # Prefix for +aref+, defined by subclasses.
186
+ other = ancestor.find_method_named('#' + name) ||
187
+ ancestor.find_attribute_named(name)
217
188
 
218
- def aref_prefix
219
- raise NotImplementedError
220
- end
189
+ return other if other
190
+ end
221
191
 
222
- ##
223
- # Attempts to sanitize the content passed by the Ruby parser:
224
- # remove outer parentheses, etc.
192
+ nil
193
+ end
225
194
 
226
- def block_params=(value)
227
- # 'yield.to_s' or 'assert yield, msg'
228
- return @block_params = '' if value =~ /^[\.,]/
195
+ ##
196
+ # Abstract method. Contexts in their building phase call this
197
+ # to register a new alias for this known method/attribute.
198
+ #
199
+ # - creates a new AnyMethod/Attribute named <tt>an_alias.new_name</tt>;
200
+ # - adds +self+ as an alias for the new method or attribute
201
+ # - adds the method or attribute to #aliases
202
+ # - adds the method or attribute to +context+.
203
+
204
+ def add_alias(an_alias, context)
205
+ raise NotImplementedError
206
+ end
229
207
 
230
- # remove trailing 'if/unless ...'
231
- return @block_params = '' if value =~ /^(if|unless)\s/
208
+ ##
209
+ # HTML fragment reference for this method
232
210
 
233
- value = $1.strip if value =~ /^(.+)\s(if|unless)\s/
211
+ def aref
212
+ type = singleton ? 'c' : 'i'
213
+ # % characters are not allowed in html names => dash instead
214
+ "#{aref_prefix}-#{type}-#{html_name}"
215
+ end
234
216
 
235
- # outer parentheses
236
- value = $1 if value =~ /^\s*\((.*)\)\s*$/
237
- value = value.strip
217
+ ##
218
+ # Prefix for +aref+, defined by subclasses.
238
219
 
239
- # proc/lambda
240
- return @block_params = $1 if value =~ /^(proc|lambda)(\s*\{|\sdo)/
220
+ def aref_prefix
221
+ raise NotImplementedError
222
+ end
241
223
 
242
- # surrounding +...+ or [...]
243
- value = $1.strip if value =~ /^\+(.*)\+$/
244
- value = $1.strip if value =~ /^\[(.*)\]$/
224
+ ##
225
+ # Attempts to sanitize the content passed by the Ruby parser:
226
+ # remove outer parentheses, etc.
245
227
 
246
- return @block_params = '' if value.empty?
228
+ def block_params=(value)
229
+ # 'yield.to_s' or 'assert yield, msg'
230
+ return @block_params = '' if value =~ /^[\.,]/
247
231
 
248
- # global variable
249
- return @block_params = 'str' if value =~ /^\$[&0-9]$/
232
+ # remove trailing 'if/unless ...'
233
+ return @block_params = '' if value =~ /^(if|unless)\s/
250
234
 
251
- # wipe out array/hash indices
252
- value.gsub!(/(\w)\[[^\[]+\]/, '\1')
235
+ value = $1.strip if value =~ /^(.+)\s(if|unless)\s/
253
236
 
254
- # remove @ from class/instance variables
255
- value.gsub!(/@@?([a-z0-9_]+)/, '\1')
237
+ # outer parentheses
238
+ value = $1 if value =~ /^\s*\((.*)\)\s*$/
239
+ value = value.strip
256
240
 
257
- # method calls => method name
258
- value.gsub!(/([A-Z:a-z0-9_]+)\.([a-z0-9_]+)(\s*\(\s*[a-z0-9_.,\s]*\s*\)\s*)?/) do
259
- case $2
260
- when 'to_s' then $1
261
- when 'const_get' then 'const'
262
- when 'new' then
263
- $1.split('::').last. # ClassName => class_name
264
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
265
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
266
- downcase
267
- else
268
- $2
269
- end
270
- end
241
+ # proc/lambda
242
+ return @block_params = $1 if value =~ /^(proc|lambda)(\s*\{|\sdo)/
271
243
 
272
- # class prefixes
273
- value.gsub!(/[A-Za-z0-9_:]+::/, '')
244
+ # surrounding +...+ or [...]
245
+ value = $1.strip if value =~ /^\+(.*)\+$/
246
+ value = $1.strip if value =~ /^\[(.*)\]$/
274
247
 
275
- # simple expressions
276
- value = $1 if value =~ /^([a-z0-9_]+)\s*[-*+\/]/
248
+ return @block_params = '' if value.empty?
277
249
 
278
- @block_params = value.strip
279
- end
250
+ # global variable
251
+ return @block_params = 'str' if value =~ /^\$[&0-9]$/
280
252
 
281
- ##
282
- # HTML id-friendly method/attribute name
253
+ # wipe out array/hash indices
254
+ value.gsub!(/(\w)\[[^\[]+\]/, '\1')
283
255
 
284
- def html_name
285
- require 'cgi/escape'
286
- require 'cgi/util' unless defined?(CGI::EscapeExt)
256
+ # remove @ from class/instance variables
257
+ value.gsub!(/@@?([a-z0-9_]+)/, '\1')
287
258
 
288
- CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
289
- end
259
+ # method calls => method name
260
+ value.gsub!(/([A-Z:a-z0-9_]+)\.([a-z0-9_]+)(\s*\(\s*[a-z0-9_.,\s]*\s*\)\s*)?/) do
261
+ case $2
262
+ when 'to_s' then $1
263
+ when 'const_get' then 'const'
264
+ when 'new'
265
+ $1.split('::').last. # ClassName => class_name
266
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
267
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
268
+ downcase
269
+ else
270
+ $2
271
+ end
272
+ end
290
273
 
291
- ##
292
- # Full method/attribute name including namespace
274
+ # class prefixes
275
+ value.gsub!(/[A-Za-z0-9_:]+::/, '')
293
276
 
294
- def full_name
295
- @full_name ||= "#{parent_name}#{pretty_name}"
296
- end
277
+ # simple expressions
278
+ value = $1 if value =~ /^([a-z0-9_]+)\s*[-*+\/]/
297
279
 
298
- def inspect # :nodoc:
299
- alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
300
- visibility = self.visibility
301
- visibility = "forced #{visibility}" if force_documentation
302
- "#<%s:0x%x %s (%s)%s>" % [
303
- self.class, object_id,
304
- full_name,
305
- visibility,
306
- alias_for,
307
- ]
308
- end
280
+ @block_params = value.strip
281
+ end
309
282
 
310
- ##
311
- # '::' for a class method/attribute, '#' for an instance method.
283
+ ##
284
+ # HTML id-friendly method/attribute name
312
285
 
313
- def name_prefix
314
- @singleton ? '::' : '#'
315
- end
286
+ def html_name
287
+ require 'cgi/escape'
288
+ require 'cgi/util' unless defined?(CGI::EscapeExt)
316
289
 
317
- ##
318
- # Method/attribute name with class/instance indicator
290
+ CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
291
+ end
319
292
 
320
- def pretty_name
321
- "#{name_prefix}#{@name}"
322
- end
293
+ ##
294
+ # Full method/attribute name including namespace
323
295
 
324
- ##
325
- # Type of method/attribute (class or instance)
296
+ def full_name
297
+ @full_name ||= "#{parent_name}#{pretty_name}"
298
+ end
326
299
 
327
- def type
328
- singleton ? 'class' : 'instance'
329
- end
300
+ def inspect # :nodoc:
301
+ alias_for =
302
+ if @is_alias_for.respond_to? :name
303
+ " (alias for #{@is_alias_for.name})"
304
+ elsif Array === @is_alias_for
305
+ " (alias for #{@is_alias_for.last})"
306
+ end
307
+ visibility = self.visibility
308
+ visibility = "forced #{visibility}" if force_documentation
309
+ "#<%s:0x%x %s (%s)%s>" % [
310
+ self.class, object_id,
311
+ full_name,
312
+ visibility,
313
+ alias_for,
314
+ ]
315
+ end
330
316
 
331
- ##
332
- # Path to this method for use with HTML generator output.
317
+ ##
318
+ # '::' for a class method/attribute, '#' for an instance method.
333
319
 
334
- def path
335
- "#{@parent.path}##{aref}"
336
- end
320
+ def name_prefix
321
+ @singleton ? '::' : '#'
322
+ end
337
323
 
338
- ##
339
- # Name of our parent with special handling for un-marshaled methods
324
+ ##
325
+ # Method/attribute name with class/instance indicator
340
326
 
341
- def parent_name
342
- @parent_name || super
343
- end
327
+ def pretty_name
328
+ "#{name_prefix}#{@name}"
329
+ end
344
330
 
345
- def pretty_print(q) # :nodoc:
346
- alias_for =
347
- if @is_alias_for.respond_to? :name then
348
- "alias for #{@is_alias_for.name}"
349
- elsif Array === @is_alias_for then
350
- "alias for #{@is_alias_for.last}"
351
- end
331
+ ##
332
+ # Type of method/attribute (class or instance)
352
333
 
353
- q.group 2, "[#{self.class.name} #{full_name} #{visibility}", "]" do
354
- if alias_for then
355
- q.breakable
356
- q.text alias_for
357
- end
334
+ def type
335
+ singleton ? 'class' : 'instance'
336
+ end
358
337
 
359
- if text then
360
- q.breakable
361
- q.text "text:"
362
- q.breakable
363
- q.pp @text
364
- end
338
+ ##
339
+ # Path to this method for use with HTML generator output.
340
+
341
+ def path
342
+ "#{@parent.path}##{aref}"
343
+ end
344
+
345
+ ##
346
+ # Name of our parent with special handling for un-marshaled methods
347
+
348
+ def parent_name
349
+ @parent_name || super
350
+ end
365
351
 
366
- unless comment.empty? then
367
- q.breakable
368
- q.text "comment:"
369
- q.breakable
370
- q.pp @comment
352
+ def pretty_print(q) # :nodoc:
353
+ alias_for =
354
+ if @is_alias_for.respond_to? :name
355
+ "alias for #{@is_alias_for.name}"
356
+ elsif Array === @is_alias_for
357
+ "alias for #{@is_alias_for.last}"
358
+ end
359
+
360
+ q.group 2, "[#{self.class.name} #{full_name} #{visibility}", "]" do
361
+ if alias_for
362
+ q.breakable
363
+ q.text alias_for
364
+ end
365
+
366
+ unless comment.empty?
367
+ q.breakable
368
+ q.text "comment:"
369
+ q.breakable
370
+ q.pp @comment
371
+ end
371
372
  end
372
373
  end
373
- end
374
374
 
375
- ##
376
- # Used by RDoc::Generator::JsonIndex to create a record for the search
377
- # engine.
378
- #
379
- # TODO: Remove this method after dropping the darkfish theme and JsonIndex generator.
380
- # Use #search_snippet instead for getting documentation snippets.
381
-
382
- def search_record
383
- [
384
- @name,
385
- full_name,
386
- @name,
387
- @parent.full_name,
388
- path,
389
- params,
390
- search_snippet,
391
- ]
392
- end
375
+ ##
376
+ # Used by RDoc::Generator::JsonIndex to create a record for the search
377
+ # engine.
378
+ #
379
+ # TODO: Remove this method after dropping the darkfish theme and JsonIndex generator.
380
+ # Use #search_snippet instead for getting documentation snippets.
381
+
382
+ def search_record
383
+ [
384
+ @name,
385
+ full_name,
386
+ @name,
387
+ @parent.full_name,
388
+ path,
389
+ params,
390
+ search_snippet,
391
+ ]
392
+ end
393
393
 
394
- ##
395
- # Returns an HTML snippet of the comment for search results.
394
+ ##
395
+ # Returns an HTML snippet of the comment for search results.
396
396
 
397
- def search_snippet
398
- return '' if @comment.empty?
397
+ def search_snippet
398
+ return '' if @comment.empty?
399
399
 
400
- snippet(@comment)
401
- end
400
+ snippet(@comment)
401
+ end
402
402
 
403
- def to_s # :nodoc:
404
- if @is_alias_for
405
- "#{self.class.name}: #{full_name} -> #{is_alias_for}"
406
- else
407
- "#{self.class.name}: #{full_name}"
403
+ def to_s # :nodoc:
404
+ if @is_alias_for
405
+ "#{self.class.name}: #{full_name} -> #{is_alias_for}"
406
+ else
407
+ "#{self.class.name}: #{full_name}"
408
+ end
408
409
  end
409
- end
410
410
 
411
- def name_ord_range # :nodoc:
412
- case name.ord
413
- when 0..64 # anything below "A"
414
- 1
415
- when 91..96 # the symbols between "Z" and "a"
416
- 2
417
- when 123..126 # 7-bit symbols above "z": "{", "|", "}", "~"
418
- 3
419
- else # everythig else can be sorted as normal
420
- 4
411
+ def name_ord_range # :nodoc:
412
+ case name.ord
413
+ when 0..64 # anything below "A"
414
+ 1
415
+ when 91..96 # the symbols between "Z" and "a"
416
+ 2
417
+ when 123..126 # 7-bit symbols above "z": "{", "|", "}", "~"
418
+ 3
419
+ else # everythig else can be sorted as normal
420
+ 4
421
+ end
421
422
  end
422
423
  end
423
424
  end