Skip to content

Commit 8e1690f

Browse files
authored
Merge pull request #567 from pat/frozen-string-literals
Updates so things work with frozen string literals
2 parents 0211fd4 + 828f851 commit 8e1690f

File tree

10 files changed

+22
-21
lines changed

10 files changed

+22
-21
lines changed

lib/thor/actions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def find_in_source_paths(file)
140140
end
141141
end
142142

143-
message = "Could not find #{file.inspect} in any of your source paths. "
143+
message = "Could not find #{file.inspect} in any of your source paths. ".dup
144144

145145
unless self.class.source_root
146146
message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "

lib/thor/actions/file_manipulation.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ def capture(*args)
340340
with_output_buffer { yield(*args) }
341341
end
342342

343-
def with_output_buffer(buf = "") #:nodoc:
343+
def with_output_buffer(buf = "".dup) #:nodoc:
344+
raise ArgumentError, "Buffer can not be a frozen object" if buf.frozen?
344345
old_buffer = output_buffer
345346
self.output_buffer = buf
346347
yield
@@ -355,7 +356,7 @@ class CapturableERB < ERB
355356
def set_eoutvar(compiler, eoutvar = "_erbout")
356357
compiler.put_cmd = "#{eoutvar}.concat"
357358
compiler.insert_cmd = "#{eoutvar}.concat"
358-
compiler.pre_cmd = ["#{eoutvar} = ''"]
359+
compiler.pre_cmd = ["#{eoutvar} = ''.dup"]
359360
compiler.post_cmd = [eoutvar]
360361
end
361362
end

lib/thor/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def handle_no_command_error(command, has_namespace = $thor_runner) #:nodoc:
500500

501501
def handle_argument_error(command, error, args, arity) #:nodoc:
502502
name = [command.ancestor_name, command.name].compact.join(" ")
503-
msg = "ERROR: \"#{basename} #{name}\" was called with "
503+
msg = "ERROR: \"#{basename} #{name}\" was called with ".dup
504504
msg << "no arguments" if args.empty?
505505
msg << "arguments " << args.inspect unless args.empty?
506506
msg << "\nUsage: #{banner(command).inspect}"

lib/thor/command.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ def run(instance, args = [])
4040
# and required options into the given usage.
4141
def formatted_usage(klass, namespace = true, subcommand = false)
4242
if ancestor_name
43-
formatted = "#{ancestor_name} " # add space
43+
formatted = "#{ancestor_name} ".dup # add space
4444
elsif namespace
4545
namespace = klass.namespace
46-
formatted = "#{namespace.gsub(/^(default)/, '')}:"
46+
formatted = "#{namespace.gsub(/^(default)/, '')}:".dup
4747
end
48-
formatted ||= "#{klass.namespace.split(':').last} " if subcommand
48+
formatted ||= "#{klass.namespace.split(':').last} ".dup if subcommand
4949

50-
formatted ||= ""
50+
formatted ||= "".dup
5151

5252
# Add usage with required arguments
5353
formatted << if klass && !klass.arguments.empty?

lib/thor/group.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def printable_commands(*)
205205
alias_method :printable_tasks, :printable_commands
206206

207207
def handle_argument_error(command, error, _args, arity) #:nodoc:
208-
msg = "#{basename} #{command.name} takes #{arity} argument"
208+
msg = "#{basename} #{command.name} takes #{arity} argument".dup
209209
msg << "s" if arity > 1
210210
msg << ", but it should not."
211211
raise error, msg

lib/thor/parser/option.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def human_name
8181

8282
def usage(padding = 0)
8383
sample = if banner && !banner.to_s.empty?
84-
"#{switch_name}=#{banner}"
84+
"#{switch_name}=#{banner}".dup
8585
else
8686
switch_name
8787
end
8888

89-
sample = "[#{sample}]" unless required?
89+
sample = "[#{sample}]".dup unless required?
9090

9191
if boolean?
9292
sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-")

lib/thor/shell/basic.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def say_status(status, message, log_status = true)
107107
status = set_color status, color, true if color
108108

109109
buffer = "#{status}#{spaces}#{message}"
110-
buffer << "\n" unless buffer.end_with?("\n")
110+
buffer = "#{buffer}\n" unless buffer.end_with?("\n")
111111

112112
stdout.print(buffer)
113113
stdout.flush
@@ -162,7 +162,7 @@ def print_table(array, options = {}) # rubocop:disable MethodLength
162162
colwidth = options[:colwidth]
163163
options[:truncate] = terminal_width if options[:truncate] == true
164164

165-
formats << "%-#{colwidth + 2}s" if colwidth
165+
formats << "%-#{colwidth + 2}s".dup if colwidth
166166
start = colwidth ? 1 : 0
167167

168168
colcount = array.max { |a, b| a.size <=> b.size }.size
@@ -174,17 +174,17 @@ def print_table(array, options = {}) # rubocop:disable MethodLength
174174
maximas << maxima
175175
formats << if index == colcount - 1
176176
# Don't output 2 trailing spaces when printing the last column
177-
"%-s"
177+
"%-s".dup
178178
else
179-
"%-#{maxima + 2}s"
179+
"%-#{maxima + 2}s".dup
180180
end
181181
end
182182

183183
formats[0] = formats[0].insert(0, " " * indent)
184184
formats << "%s"
185185

186186
array.each do |row|
187-
sentence = ""
187+
sentence = "".dup
188188

189189
row.each_with_index do |column, index|
190190
maxima = maximas[index]
@@ -412,7 +412,7 @@ def ask_simply(statement, color, options)
412412

413413
return unless result
414414

415-
result.strip!
415+
result = result.strip
416416

417417
if default && result == ""
418418
default

spec/actions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def file
204204

205205
describe "#apply" do
206206
before do
207-
@template = <<-TEMPLATE
207+
@template = <<-TEMPLATE.dup
208208
@foo = "FOO"
209209
say_status :cool, :padding
210210
TEMPLATE

spec/group_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
class_option :loud, :type => :boolean
191191

192192
def hi
193-
name.upcase! if options[:loud]
193+
self.name = name.upcase if options[:loud]
194194
"Hi #{name}"
195195
end
196196
end
@@ -207,7 +207,7 @@ def hi
207207
class_option :loud, :type => :boolean
208208

209209
def hi
210-
name.upcase! if options[:loud]
210+
self.name = name.upcase if options[:loud]
211211
out = "Hi #{name}"
212212
out << ": " << args.join(", ") unless args.empty?
213213
out

spec/thor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def bar; end
531531
method_option :loud, :type => :boolean
532532
desc "hi NAME", "say hi to name"
533533
def hi(name)
534-
name.upcase! if options[:loud]
534+
name = name.upcase if options[:loud]
535535
"Hi #{name}"
536536
end
537537
end

0 commit comments

Comments
 (0)