Skip to content

Commit 0f342fc

Browse files
committed
Remove unnecessary singleton assignments
1 parent 0923e7b commit 0f342fc

File tree

11 files changed

+16
-36
lines changed

11 files changed

+16
-36
lines changed

lib/rdoc/code_object/any_method.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ def initialize(text, name, singleton: false)
5353
# Adds +an_alias+ as an alias for this method in +context+.
5454

5555
def add_alias an_alias, context = nil
56-
method = self.class.new an_alias.text, an_alias.new_name
56+
method = self.class.new an_alias.text, an_alias.new_name, singleton: singleton
5757

5858
method.record_location an_alias.file
59-
method.singleton = self.singleton
6059
method.params = self.params
6160
method.visibility = self.visibility
6261
method.comment = an_alias.comment

lib/rdoc/code_object/class_module.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,7 @@ def marshal_load array # :nodoc:
419419
@visibility = visibility
420420

421421
methods.each do |name, file|
422-
method = RDoc::AnyMethod.new nil, name
423-
method.singleton = true if type == 'class'
422+
method = RDoc::AnyMethod.new nil, name, singleton: type == 'class'
424423
method.record_location RDoc::TopLevel.new file
425424
add_method method
426425
end

lib/rdoc/parser/c.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,10 +1013,9 @@ def handle_method(type, var_name, meth_name, function, param_count,
10131013
type = 'method' # force public
10141014
end
10151015

1016-
meth_obj = RDoc::AnyMethod.new '', meth_name
1016+
singleton = singleton || %w[singleton_method module_function].include?(type)
1017+
meth_obj = RDoc::AnyMethod.new '', meth_name, singleton: singleton
10171018
meth_obj.c_function = function
1018-
meth_obj.singleton =
1019-
singleton || %w[singleton_method module_function].include?(type)
10201019

10211020
p_count = Integer(param_count) rescue -1
10221021

lib/rdoc/parser/prism_ruby.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ def handle_meta_method_comment(comment, node)
298298
end
299299
elsif line_no || node
300300
method_name ||= call_node_name_arguments(node).first if is_call_node
301-
meth = RDoc::AnyMethod.new(@container, method_name)
302-
meth.singleton = @singleton || singleton_method
301+
meth = RDoc::AnyMethod.new(@container, method_name, singleton: @singleton || singleton_method)
303302
handle_consecutive_comment_directive(meth, comment)
304303
comment.normalize
305304
meth.call_seq = comment.extract_call_seq
@@ -315,7 +314,6 @@ def handle_meta_method_comment(comment, node)
315314
meth,
316315
line_no: line_no,
317316
visibility: visibility,
318-
singleton: @singleton || singleton_method,
319317
params: '()',
320318
calls_super: false,
321319
block_params: nil,
@@ -511,7 +509,7 @@ def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singl
511509
return if @in_proc_block
512510

513511
receiver = receiver_name ? find_or_create_module_path(receiver_name, receiver_fallback_type) : @container
514-
meth = RDoc::AnyMethod.new(nil, name)
512+
meth = RDoc::AnyMethod.new(nil, name, singleton: singleton)
515513
if (comment = consecutive_comment(start_line))
516514
handle_consecutive_comment_directive(@container, comment)
517515
handle_consecutive_comment_directive(meth, comment)
@@ -530,7 +528,6 @@ def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singl
530528
meth,
531529
line_no: start_line,
532530
visibility: visibility,
533-
singleton: singleton,
534531
params: params,
535532
calls_super: calls_super,
536533
block_params: block_params,
@@ -550,12 +547,11 @@ def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singl
550547
end
551548
end
552549

553-
private def internal_add_method(container, meth, line_no:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:) # :nodoc:
550+
private def internal_add_method(container, meth, line_no:, visibility:, params:, calls_super:, block_params:, tokens:) # :nodoc:
554551
meth.name ||= meth.call_seq[/\A[^()\s]+/] if meth.call_seq
555552
meth.name ||= 'unknown'
556553
meth.store = @store
557554
meth.line = line_no
558-
meth.singleton = singleton
559555
container.add_method(meth) # should add after setting singleton and before setting visibility
560556
meth.visibility = visibility
561557
meth.params ||= params

lib/rdoc/parser/ruby.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,9 @@ def parse_meta_method(container, single, tk, comment)
13571357

13581358
return unless name
13591359

1360-
meth = RDoc::MetaMethod.new get_tkread, name
1360+
meth = RDoc::MetaMethod.new get_tkread, name, singleton: singleton
13611361
record_location meth
13621362
meth.line = line_no
1363-
meth.singleton = singleton
13641363

13651364
remove_token_listener self
13661365

@@ -1460,9 +1459,8 @@ def parse_method(container, single, tk, comment)
14601459

14611460
return unless name
14621461

1463-
meth = RDoc::AnyMethod.new get_tkread, name
1462+
meth = RDoc::AnyMethod.new get_tkread, name, singleton: single == SINGLE ? true : singleton
14641463
look_for_directives_in meth, comment
1465-
meth.singleton = single == SINGLE ? true : singleton
14661464
if singleton
14671465
# `current_line_visibility' is useless because it works against
14681466
# the normal method named as same as the singleton method, after

test/rdoc/test_rdoc_context.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def test_add_alias_method
8989
end
9090

9191
def test_add_alias_method_singleton
92-
meth = RDoc::AnyMethod.new nil, 'old_name'
93-
meth.singleton = true
92+
meth = RDoc::AnyMethod.new nil, 'old_name', singleton: true
9493

9594
as = RDoc::Alias.new nil, 'old_name', 'new_name', 'comment', singleton: true
9695

test/rdoc/test_rdoc_cross_reference.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,9 @@ def assert_resolve_method(x)
176176
@c1.methods_hash.clear
177177

178178
i_op = RDoc::AnyMethod.new nil, x
179-
i_op.singleton = false
180179
@c1.add_method i_op
181180

182-
c_op = RDoc::AnyMethod.new nil, x
183-
c_op.singleton = true
181+
c_op = RDoc::AnyMethod.new nil, x, singleton: true
184182
@c1.add_method c_op
185183

186184
assert_ref i_op, x

test/rdoc/test_rdoc_markup_to_html_crossref.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ def test_convert_RDOCLINK_rdoc_ref_method_label
122122

123123
def test_convert_RDOCLINK_rdoc_ref_method_percent
124124
m = @c1.add_method RDoc::AnyMethod.new nil, '%'
125-
m.singleton = false
126125

127126
result = @to.convert 'rdoc-ref:C1#%'
128127

@@ -137,7 +136,6 @@ def test_convert_RDOCLINK_rdoc_ref_method_percent
137136

138137
def test_convert_RDOCLINK_rdoc_ref_method_escape_html
139138
m = @c1.add_method RDoc::AnyMethod.new nil, '<<'
140-
m.singleton = false
141139

142140
result = @to.convert 'rdoc-ref:C1#<<'
143141

@@ -151,7 +149,6 @@ def test_convert_RDOCLINK_rdoc_ref_method_escape_html
151149

152150
def test_convert_RDOCLINK_rdoc_ref_method_percent_label
153151
m = @c1.add_method RDoc::AnyMethod.new nil, '%'
154-
m.singleton = false
155152

156153
result = @to.convert 'rdoc-ref:C1#%@f'
157154

test/rdoc/test_rdoc_ri_driver.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,7 @@ def test_list_methods_matching_regexp
12141214
@cFoo.add_method index
12151215
@store1.save_method @cFoo, index
12161216

1217-
c_index = RDoc::AnyMethod.new nil, '[]'
1218-
c_index.singleton = true
1217+
c_index = RDoc::AnyMethod.new nil, '[]', singleton: true
12191218
c_index.record_location @top_level
12201219
@cFoo.add_method c_index
12211220
@store1.save_method @cFoo, c_index
@@ -1577,9 +1576,8 @@ def util_store
15771576
@bother.params = "(things)"
15781577
@bother.record_location @top_level
15791578

1580-
@new = @cFoo_Bar.add_method RDoc::AnyMethod.new nil, 'new'
1579+
@new = @cFoo_Bar.add_method RDoc::AnyMethod.new nil, 'new', singleton: true
15811580
@new.record_location @top_level
1582-
@new.singleton = true
15831581

15841582
@attr = @cFoo_Bar.add_attribute RDoc::Attr.new nil, 'attr', 'RW', ''
15851583
@attr.record_location @top_level

test/rdoc/test_rdoc_stats.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,12 @@ def test_report_method_class
397397
c.record_location @tl
398398
c.add_comment 'C', @tl
399399

400-
m1 = RDoc::AnyMethod.new nil, 'm1'
400+
m1 = RDoc::AnyMethod.new nil, 'm1', singleton: true
401401
m1.record_location @tl
402-
m1.singleton = true
403402
c.add_method m1
404403

405-
m2 = RDoc::AnyMethod.new nil, 'm2'
404+
m2 = RDoc::AnyMethod.new nil, 'm2', singleton: true
406405
m2.record_location @tl
407-
m2.singleton = true
408406
c.add_method m2
409407
m2.comment = 'm2'
410408

0 commit comments

Comments
 (0)