Append to Strings with #<< rather than #+.

This commit is contained in:
Shannon Skipper 2013-11-11 22:54:31 -08:00
parent 3e31d01d0b
commit 16c08857a6
14 changed files with 29 additions and 30 deletions

View File

@ -114,7 +114,7 @@ Copyright (c) 2013 John Mair (banisterfiend)
--
}
on :e, :exec=, "A line of code to execute in context before the session starts" do |input|
exec_string << input + "\n"
exec_string << input << "\n"
end
on "no-pager", "Disable pager for long output" do
@ -155,7 +155,7 @@ Copyright (c) 2013 John Mair (banisterfiend)
puts "Installed Plugins:"
puts "--"
Pry.locate_plugins.each do |plugin|
puts "#{plugin.name}".ljust(18) + plugin.spec.summary
puts "#{plugin.name}".ljust(18) << plugin.spec.summary
end
exit
end

View File

@ -356,7 +356,7 @@ class Pry
#
# @return [String]
def raw
@lines.map(&:line).join("\n") + "\n"
@lines.map(&:line).join("\n") << "\n"
end
# Return the number of lines stored.

View File

@ -307,8 +307,7 @@ class Pry
collision_type ||= 'local-variable' if arg_string.match(%r{\A\s*[-+*/%&|^]*=})
if collision_type
output.puts "#{text.bold('WARNING:')} Calling Pry command '#{command_match}'," +
"which conflicts with a #{collision_type}.\n\n"
output.puts "#{text.bold('WARNING:')} Calling Pry command '#{command_match}', which conflicts with a #{collision_type}.\n\n"
end
rescue Pry::RescuableException
end

View File

@ -410,7 +410,7 @@ class Pry
else
commands.keys.select do |key|
String === key && key.start_with?(search)
end.map{ |key| key + " " } + Bond::DefaultMission.completions
end.map{ |key| key + " " } << Bond::DefaultMission.completions
end
end
end

View File

@ -1,6 +1,6 @@
# Default commands used by Pry.
Pry::Commands = Pry::CommandSet.new
Dir[File.expand_path('../commands', __FILE__) + '/*.rb'].each do |file|
Dir[File.expand_path('../commands', __FILE__) << '/*.rb'].each do |file|
require file
end

View File

@ -48,11 +48,11 @@ class Pry
def insert_into_array(array, range)
insert_slot = Array(range).first
array.insert(insert_slot, arg_string[1..-1] + "\n")
array.insert(insert_slot, arg_string[1..-1] << "\n")
end
def replace_in_array(array, range)
array[range] = arg_string + "\n"
array[range] = arg_string << "\n"
end
# @return [Fixnum] The number of lines currently in `eval_string` (the input buffer).

View File

@ -97,7 +97,7 @@ class Pry
output.puts text.bold(klass.name)
grouped[klass].each do |method|
header = method.name_with_owner
output.puts header + additional_info(header, method)
output.puts header << additional_info(header, method)
end
end
@ -105,7 +105,7 @@ class Pry
# if `-c` was not given
def additional_info(header, method)
if opts.content?
": " + colorize_code(matched_method_lines(header, method))
": " << colorize_code(matched_method_lines(header, method))
else
""
end

View File

@ -59,7 +59,7 @@ class Pry
# @param [Array<Pry::Command>]] commands
# @return [String] The generated help string.
def help_text_for_commands(name, commands)
"#{text.bold(name)}\n" + commands.map do |command|
"#{text.bold(name)}\n" << commands.map do |command|
" #{command.options[:listing].to_s.ljust(18)} #{command.description}"
end.join("\n")
end

View File

@ -34,8 +34,8 @@ class Pry
opt.on :v, :verbose, "Show methods and constants on all super-classes (ignores Pry.config.ls.ceiling)"
opt.on :g, :globals, "Show global variables, including those builtin to Ruby (in cyan)"
opt.on :l, :locals, "Show hash of local vars, sorted by descending size"
opt.on :c, :constants, "Show constants, highlighting classes (in blue), and exceptions (in purple).\n" +
" " * 32 + "Constants that are pending autoload? are also shown (in yellow)"
opt.on :c, :constants, "Show constants, highlighting classes (in blue), and exceptions (in purple).\n" <<
" " * 32 << "Constants that are pending autoload? are also shown (in yellow)"
opt.on :i, :ivars, "Show instance variables (in blue) and class variables (in bright blue)"
opt.on :G, :grep, "Filter output by regular expression", :argument => true

View File

@ -17,8 +17,8 @@ class Pry
BANNER
def process
stagger_output text.bold('Backtrace:') +
"\n--\n" + _pry_.backtrace.join("\n")
stagger_output text.bold('Backtrace:') <<
"\n--\n" << _pry_.backtrace.join("\n")
end
end

View File

@ -63,7 +63,7 @@ class Pry
end
def content_and_header_for_code_object(code_object)
header(code_object) + content_for(code_object)
header(code_object) << content_for(code_object)
end
def content_and_headers_for_all_module_candidates(mod)
@ -95,7 +95,7 @@ class Pry
h << code_object_header(code_object, line_num)
h << "\n#{Pry::Helpers::Text.bold('Number of lines:')} " <<
"#{content_for(code_object).lines.count}\n\n"
h << Helpers::Text.bold('** Warning:') + " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
h << Helpers::Text.bold('** Warning:') << " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
h
end
@ -128,7 +128,7 @@ class Pry
h << " #{text.bold('name:')} #{code_object.nonblank_name}"
if code_object.number_of_candidates > 1
h << (text.bold("\nNumber of monkeypatches: ") + code_object.number_of_candidates.to_s)
h << (text.bold("\nNumber of monkeypatches: ") << code_object.number_of_candidates.to_s)
h << ". Use the `-a` option to display all available monkeypatches"
end
h

View File

@ -88,8 +88,8 @@ class Pry
set_file_and_dir_locals(@file)
out = "\n#{text.bold('From:')} #{location}:\n\n" +
code.with_line_numbers(use_line_numbers?).with_marker(marker).to_s + "\n"
out = "\n#{text.bold('From:')} #{location}:\n\n" <<
code.with_line_numbers(use_line_numbers?).with_marker(marker).to_s << "\n"
stagger_output(out)
end

View File

@ -112,7 +112,7 @@ class Pry
# Symbol
if Symbol.respond_to?(:all_symbols)
sym = Regexp.quote($1)
candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
candidates = Symbol.all_symbols.collect{|s| ":" << s.id2name}
candidates.grep(/^#{sym}/)
else
@ -123,7 +123,7 @@ class Pry
# Absolute Constant or class methods
receiver = $1
candidates = Object.constants.collect(&:to_s)
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
candidates.grep(/^#{receiver}/).collect{|e| "::" << e}
# Complete target symbols
@ -151,7 +151,7 @@ class Pry
rescue RescuableException
candidates = []
end
candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
candidates.grep(/^#{message}/).collect{|e| receiver << "::" << e}
when /^(:[^:.]+)\.([^.]*)$/
# Symbol
@ -261,10 +261,10 @@ class Pry
candidates.grep(/^#{message}/).collect { |e|
case e
when /^[a-zA-Z_]/
path.call(receiver + "." + e)
path.call(receiver + "." << e)
when /^[0-9]/
when *Operators
#receiver + " " + e
#receiver + " " << e
end
}.compact
end

View File

@ -94,8 +94,8 @@ class Pry
indent = new
lines = str.split("\n")
n = line_number - 1
to_indent = lines[0...n] + (lines[n] || "").split("def").first(1)
indent.indent(to_indent.join("\n") + "\n")
to_indent = lines[0...n] << (lines[n] || "").split("def").first(1)
indent.indent(to_indent.join("\n") << "\n")
indent.module_nesting
end
@ -156,7 +156,7 @@ class Pry
before.times{ prefix.sub! SPACES, '' }
new_prefix = prefix + SPACES * after
line = prefix + line.lstrip unless previously_in_string
line = prefix << line.lstrip unless previously_in_string
output += line
@ -384,7 +384,7 @@ class Pry
# @return [String]
def correct_indentation(prompt, code, overhang=0)
prompt = prompt.delete("\001\002")
line_to_measure = Pry::Helpers::Text.strip_color(prompt) + code
line_to_measure = Pry::Helpers::Text.strip_color(prompt) << code
whitespace = ' ' * overhang
_, cols = Terminal.screen_size