Append to Strings with #<< rather than #+.
This commit is contained in:
parent
3e31d01d0b
commit
16c08857a6
|
@ -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|
|
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
|
end
|
||||||
|
|
||||||
on "no-pager", "Disable pager for long output" do
|
on "no-pager", "Disable pager for long output" do
|
||||||
|
@ -155,7 +155,7 @@ Copyright (c) 2013 John Mair (banisterfiend)
|
||||||
puts "Installed Plugins:"
|
puts "Installed Plugins:"
|
||||||
puts "--"
|
puts "--"
|
||||||
Pry.locate_plugins.each do |plugin|
|
Pry.locate_plugins.each do |plugin|
|
||||||
puts "#{plugin.name}".ljust(18) + plugin.spec.summary
|
puts "#{plugin.name}".ljust(18) << plugin.spec.summary
|
||||||
end
|
end
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
|
@ -356,7 +356,7 @@ class Pry
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def raw
|
def raw
|
||||||
@lines.map(&:line).join("\n") + "\n"
|
@lines.map(&:line).join("\n") << "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the number of lines stored.
|
# Return the number of lines stored.
|
||||||
|
|
|
@ -307,8 +307,7 @@ class Pry
|
||||||
collision_type ||= 'local-variable' if arg_string.match(%r{\A\s*[-+*/%&|^]*=})
|
collision_type ||= 'local-variable' if arg_string.match(%r{\A\s*[-+*/%&|^]*=})
|
||||||
|
|
||||||
if collision_type
|
if collision_type
|
||||||
output.puts "#{text.bold('WARNING:')} Calling Pry command '#{command_match}'," +
|
output.puts "#{text.bold('WARNING:')} Calling Pry command '#{command_match}', which conflicts with a #{collision_type}.\n\n"
|
||||||
"which conflicts with a #{collision_type}.\n\n"
|
|
||||||
end
|
end
|
||||||
rescue Pry::RescuableException
|
rescue Pry::RescuableException
|
||||||
end
|
end
|
||||||
|
|
|
@ -410,7 +410,7 @@ class Pry
|
||||||
else
|
else
|
||||||
commands.keys.select do |key|
|
commands.keys.select do |key|
|
||||||
String === key && key.start_with?(search)
|
String === key && key.start_with?(search)
|
||||||
end.map{ |key| key + " " } + Bond::DefaultMission.completions
|
end.map{ |key| key + " " } << Bond::DefaultMission.completions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Default commands used by Pry.
|
# Default commands used by Pry.
|
||||||
Pry::Commands = Pry::CommandSet.new
|
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
|
require file
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,11 +48,11 @@ class Pry
|
||||||
|
|
||||||
def insert_into_array(array, range)
|
def insert_into_array(array, range)
|
||||||
insert_slot = Array(range).first
|
insert_slot = Array(range).first
|
||||||
array.insert(insert_slot, arg_string[1..-1] + "\n")
|
array.insert(insert_slot, arg_string[1..-1] << "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_in_array(array, range)
|
def replace_in_array(array, range)
|
||||||
array[range] = arg_string + "\n"
|
array[range] = arg_string << "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Fixnum] The number of lines currently in `eval_string` (the input buffer).
|
# @return [Fixnum] The number of lines currently in `eval_string` (the input buffer).
|
||||||
|
|
|
@ -97,7 +97,7 @@ class Pry
|
||||||
output.puts text.bold(klass.name)
|
output.puts text.bold(klass.name)
|
||||||
grouped[klass].each do |method|
|
grouped[klass].each do |method|
|
||||||
header = method.name_with_owner
|
header = method.name_with_owner
|
||||||
output.puts header + additional_info(header, method)
|
output.puts header << additional_info(header, method)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class Pry
|
||||||
# if `-c` was not given
|
# if `-c` was not given
|
||||||
def additional_info(header, method)
|
def additional_info(header, method)
|
||||||
if opts.content?
|
if opts.content?
|
||||||
": " + colorize_code(matched_method_lines(header, method))
|
": " << colorize_code(matched_method_lines(header, method))
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ class Pry
|
||||||
# @param [Array<Pry::Command>]] commands
|
# @param [Array<Pry::Command>]] commands
|
||||||
# @return [String] The generated help string.
|
# @return [String] The generated help string.
|
||||||
def help_text_for_commands(name, commands)
|
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}"
|
" #{command.options[:listing].to_s.ljust(18)} #{command.description}"
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
end
|
end
|
||||||
|
|
|
@ -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 :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 :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 :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" +
|
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)"
|
" " * 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 :i, :ivars, "Show instance variables (in blue) and class variables (in bright blue)"
|
||||||
opt.on :G, :grep, "Filter output by regular expression", :argument => true
|
opt.on :G, :grep, "Filter output by regular expression", :argument => true
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ class Pry
|
||||||
BANNER
|
BANNER
|
||||||
|
|
||||||
def process
|
def process
|
||||||
stagger_output text.bold('Backtrace:') +
|
stagger_output text.bold('Backtrace:') <<
|
||||||
"\n--\n" + _pry_.backtrace.join("\n")
|
"\n--\n" << _pry_.backtrace.join("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_and_header_for_code_object(code_object)
|
def content_and_header_for_code_object(code_object)
|
||||||
header(code_object) + content_for(code_object)
|
header(code_object) << content_for(code_object)
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_and_headers_for_all_module_candidates(mod)
|
def content_and_headers_for_all_module_candidates(mod)
|
||||||
|
@ -95,7 +95,7 @@ class Pry
|
||||||
h << code_object_header(code_object, line_num)
|
h << code_object_header(code_object, line_num)
|
||||||
h << "\n#{Pry::Helpers::Text.bold('Number of lines:')} " <<
|
h << "\n#{Pry::Helpers::Text.bold('Number of lines:')} " <<
|
||||||
"#{content_for(code_object).lines.count}\n\n"
|
"#{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
|
h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ class Pry
|
||||||
h << " #{text.bold('name:')} #{code_object.nonblank_name}"
|
h << " #{text.bold('name:')} #{code_object.nonblank_name}"
|
||||||
|
|
||||||
if code_object.number_of_candidates > 1
|
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"
|
h << ". Use the `-a` option to display all available monkeypatches"
|
||||||
end
|
end
|
||||||
h
|
h
|
||||||
|
|
|
@ -88,8 +88,8 @@ class Pry
|
||||||
|
|
||||||
set_file_and_dir_locals(@file)
|
set_file_and_dir_locals(@file)
|
||||||
|
|
||||||
out = "\n#{text.bold('From:')} #{location}:\n\n" +
|
out = "\n#{text.bold('From:')} #{location}:\n\n" <<
|
||||||
code.with_line_numbers(use_line_numbers?).with_marker(marker).to_s + "\n"
|
code.with_line_numbers(use_line_numbers?).with_marker(marker).to_s << "\n"
|
||||||
|
|
||||||
stagger_output(out)
|
stagger_output(out)
|
||||||
end
|
end
|
||||||
|
|
|
@ -112,7 +112,7 @@ class Pry
|
||||||
# Symbol
|
# Symbol
|
||||||
if Symbol.respond_to?(:all_symbols)
|
if Symbol.respond_to?(:all_symbols)
|
||||||
sym = Regexp.quote($1)
|
sym = Regexp.quote($1)
|
||||||
candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
|
candidates = Symbol.all_symbols.collect{|s| ":" << s.id2name}
|
||||||
|
|
||||||
candidates.grep(/^#{sym}/)
|
candidates.grep(/^#{sym}/)
|
||||||
else
|
else
|
||||||
|
@ -123,7 +123,7 @@ class Pry
|
||||||
# Absolute Constant or class methods
|
# Absolute Constant or class methods
|
||||||
receiver = $1
|
receiver = $1
|
||||||
candidates = Object.constants.collect(&:to_s)
|
candidates = Object.constants.collect(&:to_s)
|
||||||
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
|
candidates.grep(/^#{receiver}/).collect{|e| "::" << e}
|
||||||
|
|
||||||
|
|
||||||
# Complete target symbols
|
# Complete target symbols
|
||||||
|
@ -151,7 +151,7 @@ class Pry
|
||||||
rescue RescuableException
|
rescue RescuableException
|
||||||
candidates = []
|
candidates = []
|
||||||
end
|
end
|
||||||
candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
|
candidates.grep(/^#{message}/).collect{|e| receiver << "::" << e}
|
||||||
|
|
||||||
when /^(:[^:.]+)\.([^.]*)$/
|
when /^(:[^:.]+)\.([^.]*)$/
|
||||||
# Symbol
|
# Symbol
|
||||||
|
@ -261,10 +261,10 @@ class Pry
|
||||||
candidates.grep(/^#{message}/).collect { |e|
|
candidates.grep(/^#{message}/).collect { |e|
|
||||||
case e
|
case e
|
||||||
when /^[a-zA-Z_]/
|
when /^[a-zA-Z_]/
|
||||||
path.call(receiver + "." + e)
|
path.call(receiver + "." << e)
|
||||||
when /^[0-9]/
|
when /^[0-9]/
|
||||||
when *Operators
|
when *Operators
|
||||||
#receiver + " " + e
|
#receiver + " " << e
|
||||||
end
|
end
|
||||||
}.compact
|
}.compact
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,8 +94,8 @@ class Pry
|
||||||
indent = new
|
indent = new
|
||||||
lines = str.split("\n")
|
lines = str.split("\n")
|
||||||
n = line_number - 1
|
n = line_number - 1
|
||||||
to_indent = lines[0...n] + (lines[n] || "").split("def").first(1)
|
to_indent = lines[0...n] << (lines[n] || "").split("def").first(1)
|
||||||
indent.indent(to_indent.join("\n") + "\n")
|
indent.indent(to_indent.join("\n") << "\n")
|
||||||
indent.module_nesting
|
indent.module_nesting
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class Pry
|
||||||
before.times{ prefix.sub! SPACES, '' }
|
before.times{ prefix.sub! SPACES, '' }
|
||||||
new_prefix = prefix + SPACES * after
|
new_prefix = prefix + SPACES * after
|
||||||
|
|
||||||
line = prefix + line.lstrip unless previously_in_string
|
line = prefix << line.lstrip unless previously_in_string
|
||||||
|
|
||||||
output += line
|
output += line
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ class Pry
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def correct_indentation(prompt, code, overhang=0)
|
def correct_indentation(prompt, code, overhang=0)
|
||||||
prompt = prompt.delete("\001\002")
|
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
|
whitespace = ' ' * overhang
|
||||||
|
|
||||||
_, cols = Terminal.screen_size
|
_, cols = Terminal.screen_size
|
||||||
|
|
Loading…
Reference in New Issue