Skip to content

Commit

Permalink
Simplify section add/remove comment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Jan 1, 2025
1 parent 906a72b commit 4955198
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/rdoc/code_object/context/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@ def == other
# Adds +comment+ to this section

def add_comment comment
if comment.is_a?(Array)
comment.each do |c|
@comments << extract_comment(c)
end
else
comment = extract_comment(comment)
@comments << comment unless comment.empty?
comments = Array(comment)
comments.each do |c|
extracted_comment = extract_comment(c)
@comments << extracted_comment unless extracted_comment.empty?
end
end

Expand Down Expand Up @@ -123,9 +120,7 @@ def hash # :nodoc:
# The files comments in this section come from

def in_files
@comments.map do |comment|
comment.file
end
@comments.map(&:file)
end

##
Expand Down Expand Up @@ -171,9 +166,9 @@ def plain_html
# Removes a comment from this section if it is from the same file as
# +comment+

def remove_comment comment
@comments.delete_if do |my_comment|
my_comment.file == comment.file
def remove_comment target_comment
@comments.delete_if do |stored_comment|
stored_comment.file == target_comment.file
end
end

Expand Down

0 comments on commit 4955198

Please sign in to comment.