1- # frozen_string_literal: false
1+ # frozen_string_literal: true
22##
33# A comment holds the text comment for a RDoc::CodeObject and provides a
44# unified way of cleaning it up and parsing it into an RDoc::Markup::Document.
@@ -45,7 +45,7 @@ class RDoc::Comment
4545
4646 def initialize text = nil , location = nil
4747 @location = location
48- @text = text
48+ @text = text . nil? ? nil : text . dup
4949
5050 @document = nil
5151 @format = 'rdoc'
@@ -114,10 +114,14 @@ def extract_call_seq method
114114
115115 method . call_seq = seq . chomp
116116
117- elsif @text . sub! ( /^\s *:?call-seq:(.*?)(^\s *$|\z )/m , '' ) then
118- seq = $1
119- seq . gsub! ( /^\s */ , '' )
120- method . call_seq = seq
117+ else
118+ regexp = /^\s *:?call-seq:(.*?)(^\s *$|\z )/m
119+ if regexp =~ @text then
120+ @text = @text . sub ( regexp , '' )
121+ seq = $1
122+ seq . gsub! ( /^\s */ , '' )
123+ method . call_seq = seq
124+ end
121125 end
122126
123127 method
@@ -133,8 +137,14 @@ def empty?
133137 ##
134138 # HACK dubious
135139
136- def force_encoding encoding
137- @text . force_encoding encoding
140+ def encode! encoding
141+ # TODO: Remove this condition after Ruby 2.2 EOL
142+ if RUBY_VERSION < '2.3.0'
143+ @text = @text . force_encoding encoding
144+ else
145+ @text = String . new @text , encoding : encoding
146+ end
147+ self
138148 end
139149
140150 ##
@@ -200,7 +210,7 @@ def parse
200210 def remove_private
201211 # Workaround for gsub encoding for Ruby 1.9.2 and earlier
202212 empty = ''
203- empty . force_encoding @text . encoding
213+ empty = RDoc :: Encoding . change_encoding empty , @text . encoding
204214
205215 @text = @text . gsub ( %r%^\s *([#*]?)--.*?^\s *(\1 )\+ \+ \n ?%m , empty )
206216 @text = @text . sub ( %r%^\s *[#*]?--.*%m , '' )
@@ -216,7 +226,7 @@ def text= text
216226 @text . nil? and @document
217227
218228 @document = nil
219- @text = text
229+ @text = text . nil? ? nil : text . dup
220230 end
221231
222232 ##
0 commit comments