Skip to content

Commit ebd7cf8

Browse files
authored
Merge pull request #688 from aycabta/ClassModule_add_comment-should-receive-RDocComment
ClassModule#add_comment should receive RDoc::Comment
2 parents 9dea147 + 3fb03bf commit ebd7cf8

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

lib/rdoc/class_module.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def comment= comment # :nodoc:
210210
normalize_comment comment
211211
end
212212

213-
comment = "#{@comment}\n---\n#{comment}" unless @comment.empty?
213+
comment = "#{@comment.to_s}\n---\n#{comment.to_s}" unless @comment.empty?
214214

215215
super comment
216216
end

lib/rdoc/comment.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class RDoc::Comment
3333

3434
attr_reader :text
3535

36+
##
37+
# Alias for text
38+
39+
alias to_s text
40+
3641
##
3742
# Overrides the content returned by #parse. Use when there is no #text
3843
# source for this comment

test/test_rdoc_class_module.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@ def test_add_comment
99
tl3 = @store.add_file 'three.rb'
1010

1111
cm = RDoc::ClassModule.new 'Klass'
12-
cm.add_comment '# comment 1', tl1
12+
comment_tl1 = RDoc::Comment.new('# comment 1')
13+
cm.add_comment comment_tl1, tl1
1314

14-
assert_equal [['comment 1', tl1]], cm.comment_location
15-
assert_equal 'comment 1', cm.comment
15+
assert_equal [[comment_tl1, tl1]], cm.comment_location
16+
assert_equal 'comment 1', cm.comment.text
1617

17-
cm.add_comment '# comment 2', tl2
18+
comment_tl2 = RDoc::Comment.new('# comment 2')
19+
cm.add_comment comment_tl2, tl2
1820

19-
assert_equal [['comment 1', tl1], ['comment 2', tl2]], cm.comment_location
21+
assert_equal [[comment_tl1, tl1], [comment_tl2, tl2]], cm.comment_location
2022
assert_equal "comment 1\n---\ncomment 2", cm.comment
2123

22-
cm.add_comment "# * comment 3", tl3
24+
comment_tl3 = RDoc::Comment.new('# * comment 3')
25+
cm.add_comment comment_tl3, tl3
2326

24-
assert_equal [['comment 1', tl1],
25-
['comment 2', tl2],
26-
['* comment 3', tl3]], cm.comment_location
27+
assert_equal [[comment_tl1, tl1],
28+
[comment_tl2, tl2],
29+
[comment_tl3, tl3]], cm.comment_location
2730
assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
2831
end
2932

0 commit comments

Comments
 (0)