summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-03-02 02:03:35 +0200
committerKyrylo Silin <silin@kyrylo.org>2019-03-02 11:03:54 +0200
commit39fa8a9fc6a6dad34464f91ae0a08107fe9a9730 (patch)
treea810b1bfad889c782f8d02b1a28a4cd571e506db
parent8ea5b6e0aa3405ee157aa1c7756a5619324d1bfd (diff)
downloadpry-39fa8a9fc6a6dad34464f91ae0a08107fe9a9730.tar.gz
rubocop: fix offences of the Style/IfUnlessModifier cop
-rw-r--r--.rubocop_todo.yml5
-rw-r--r--Gemfile4
-rw-r--r--lib/pry.rb4
-rw-r--r--lib/pry/cli.rb12
-rw-r--r--lib/pry/code.rb8
-rw-r--r--lib/pry/command.rb4
-rw-r--r--lib/pry/command_set.rb8
-rw-r--r--lib/pry/commands/cd.rb4
-rw-r--r--lib/pry/commands/edit.rb4
-rw-r--r--lib/pry/commands/gist.rb8
-rw-r--r--lib/pry/commands/help.rb4
-rw-r--r--lib/pry/commands/hist.rb16
-rw-r--r--lib/pry/commands/ls.rb8
-rw-r--r--lib/pry/commands/ls/methods_helper.rb4
-rw-r--r--lib/pry/commands/play.rb4
-rw-r--r--lib/pry/commands/reload_code.rb4
-rw-r--r--lib/pry/commands/ri.rb4
-rw-r--r--lib/pry/commands/shell_command.rb4
-rw-r--r--lib/pry/commands/show_info.rb4
-rw-r--r--lib/pry/commands/watch_expression.rb4
-rw-r--r--lib/pry/commands/whereami.rb8
-rw-r--r--lib/pry/config/behavior.rb4
-rw-r--r--lib/pry/helpers/command_helpers.rb8
-rw-r--r--lib/pry/history.rb12
-rw-r--r--lib/pry/hooks.rb8
-rw-r--r--lib/pry/indent.rb4
-rw-r--r--lib/pry/input_completer.rb8
-rw-r--r--lib/pry/method.rb12
-rw-r--r--lib/pry/method/weird_method_locator.rb4
-rw-r--r--lib/pry/pager.rb8
-rw-r--r--lib/pry/plugins.rb4
-rw-r--r--lib/pry/prompt.rb8
-rw-r--r--lib/pry/pry_class.rb8
-rw-r--r--lib/pry/pry_instance.rb12
-rw-r--r--lib/pry/repl.rb16
-rw-r--r--lib/pry/slop.rb28
-rw-r--r--lib/pry/slop/commands.rb12
-rw-r--r--lib/pry/slop/option.rb16
-rw-r--r--lib/pry/terminal.rb8
-rw-r--r--lib/pry/testable/evalable.rb4
-rw-r--r--lib/pry/testable/pry_tester.rb4
-rw-r--r--lib/pry/wrapped_module.rb4
-rw-r--r--spec/commands/show_doc_spec.rb4
-rw-r--r--spec/commands/wtf_spec.rb4
-rw-r--r--spec/spec_helpers/repl_tester.rb4
45 files changed, 81 insertions, 248 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 4e1adfba..845d1e36 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -274,11 +274,6 @@ Style/IfInsideElse:
- 'lib/pry/slop/commands.rb'
- 'lib/pry/slop/option.rb'
-# Offense count: 79
-# Cop supports --auto-correct.
-Style/IfUnlessModifier:
- Enabled: false
-
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: InverseMethods, InverseBlocks.
diff --git a/Gemfile b/Gemfile
index 383cc040..3fea6ab6 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,9 +7,7 @@ group :development do
gem 'yard'
# Rubocop supports only >=2.2.0
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
- gem 'rubocop', '= 0.65.0', require: false
- end
+ gem 'rubocop', '= 0.65.0', require: false if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
end
group :test do
diff --git a/lib/pry.rb b/lib/pry.rb
index 5494fef0..4ce2fb83 100644
--- a/lib/pry.rb
+++ b/lib/pry.rb
@@ -75,9 +75,7 @@ class Pry
end
DEFAULT_SYSTEM = proc do |output, cmd, _|
- if !system(cmd)
- output.puts "Error: there was a problem executing system command: #{cmd}"
- end
+ output.puts "Error: there was a problem executing system command: #{cmd}" if !system(cmd)
end
# This is to keep from breaking under Rails 3.2 for people who are doing that
diff --git a/lib/pry/cli.rb b/lib/pry/cli.rb
index f7109691..9af1d7dd 100644
--- a/lib/pry/cli.rb
+++ b/lib/pry/cli.rb
@@ -55,9 +55,7 @@ class Pry
end
def parse_options(args = ARGV)
- unless options
- raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options."
- end
+ raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options." unless options
@pass_argv = args.index { |cli_arg| %w[- --].include?(cli_arg) }
if @pass_argv
@@ -85,9 +83,7 @@ class Pry
Pry.final_session_setup
# Option processors are optional.
- if option_processors
- option_processors.each { |processor| processor.call(opts) }
- end
+ option_processors.each { |processor| processor.call(opts) } if option_processors
opts
end
@@ -129,9 +125,7 @@ Pry::Slop.new do
end
end.parse(ARGV.dup)
-if Pry.config.should_load_plugins
- Pry::CLI.add_plugin_options
-end
+Pry::CLI.add_plugin_options if Pry.config.should_load_plugins
# The default Pry command line options (before plugin options are included)
Pry::CLI.add_options do
diff --git a/lib/pry/code.rb b/lib/pry/code.rb
index 0c5117d1..037b5c45 100644
--- a/lib/pry/code.rb
+++ b/lib/pry/code.rb
@@ -85,9 +85,7 @@ class Pry
# @param [Integer?] start_line
# @param [Symbol?] code_type
def initialize(lines = [], start_line = 1, code_type = :ruby)
- if lines.is_a? String
- lines = lines.lines
- end
+ lines = lines.lines if lines.is_a? String
@lines = lines.each_with_index.map do |line, lineno|
LOC.new(line, lineno + start_line.to_i)
end
@@ -103,9 +101,7 @@ class Pry
# @param [Integer?] lineno
# @return [String] The inserted line.
def push(line, lineno = nil)
- if lineno.nil?
- lineno = @lines.last.lineno + 1
- end
+ lineno = @lines.last.lineno + 1 if lineno.nil?
@lines.push(LOC.new(line, lineno))
line
end
diff --git a/lib/pry/command.rb b/lib/pry/command.rb
index 9d7facbd..b6cbd8f1 100644
--- a/lib/pry/command.rb
+++ b/lib/pry/command.rb
@@ -429,9 +429,7 @@ WARN
return void
end
- if command_options[:argument_required] && args.empty?
- raise CommandError, "The command '#{command_name}' requires an argument."
- end
+ raise CommandError, "The command '#{command_name}' requires an argument." if command_options[:argument_required] && args.empty?
ret = use_unpatched_symbol do
call_with_hooks(*args)
diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb
index 2f08848d..57866822 100644
--- a/lib/pry/command_set.rb
+++ b/lib/pry/command_set.rb
@@ -310,12 +310,8 @@ class Pry
# Pry.config.commands["help"] = MyHelpCommand
#
def []=(pattern, command)
- if command.equal?(nil)
- return @commands.delete(pattern)
- end
- unless Class === command && command < Pry::Command
- raise TypeError, "command is not a subclass of Pry::Command"
- end
+ return @commands.delete(pattern) if command.equal?(nil)
+ raise TypeError, "command is not a subclass of Pry::Command" unless Class === command && command < Pry::Command
bind_command_to_pattern = pattern != command.match
if bind_command_to_pattern
diff --git a/lib/pry/commands/cd.rb b/lib/pry/commands/cd.rb
index 6b85586e..326319dd 100644
--- a/lib/pry/commands/cd.rb
+++ b/lib/pry/commands/cd.rb
@@ -24,9 +24,7 @@ class Pry
state.old_stack ||= []
if arg_string.strip == "-"
- unless state.old_stack.empty?
- _pry_.binding_stack, state.old_stack = state.old_stack, _pry_.binding_stack
- end
+ _pry_.binding_stack, state.old_stack = state.old_stack, _pry_.binding_stack unless state.old_stack.empty?
else
stack = ObjectPath.new(arg_string, _pry_.binding_stack).resolve
diff --git a/lib/pry/commands/edit.rb b/lib/pry/commands/edit.rb
index 3ea4d5c6..6d801af6 100644
--- a/lib/pry/commands/edit.rb
+++ b/lib/pry/commands/edit.rb
@@ -39,9 +39,7 @@ class Pry
end
def process
- if bad_option_combination?
- raise CommandError, "Only one of --ex, --temp, --in, --method and FILE may be specified."
- end
+ raise CommandError, "Only one of --ex, --temp, --in, --method and FILE may be specified." if bad_option_combination?
if repl_edit?
# code defined in pry, eval'd within pry.
diff --git a/lib/pry/commands/gist.rb b/lib/pry/commands/gist.rb
index d9574992..c397bca4 100644
--- a/lib/pry/commands/gist.rb
+++ b/lib/pry/commands/gist.rb
@@ -32,9 +32,7 @@ class Pry
cc = CodeCollector.new(args, opts, _pry_)
- if cc.content =~ /\A\s*\z/
- raise CommandError, "Found no code to gist."
- end
+ raise CommandError, "Found no code to gist." if cc.content =~ /\A\s*\z/
if opts.present?(:clip)
clipboard_content(cc.content)
@@ -59,9 +57,7 @@ class Pry
corrected_index = index + range.first
if code && code != ""
content << code
- if code !~ /;\Z/
- content << "#{comment_expression_result_for_gist(_pry_.config.gist.inspecter.call(_pry_.output_ring[corrected_index]))}"
- end
+ content << "#{comment_expression_result_for_gist(_pry_.config.gist.inspecter.call(_pry_.output_ring[corrected_index]))}" if code !~ /;\Z/
end
end
end
diff --git a/lib/pry/commands/help.rb b/lib/pry/commands/help.rb
index 512ef3e6..f55f302b 100644
--- a/lib/pry/commands/help.rb
+++ b/lib/pry/commands/help.rb
@@ -45,9 +45,7 @@ class Pry
sorted_group_names(groups).each do |group_name|
commands = sorted_commands(groups[group_name])
- if commands.any?
- help_text << help_text_for_commands(group_name, commands)
- end
+ help_text << help_text_for_commands(group_name, commands) if commands.any?
end
_pry_.pager.page help_text.join("\n\n")
diff --git a/lib/pry/commands/hist.rb b/lib/pry/commands/hist.rb
index 16340216..3f14fb5c 100644
--- a/lib/pry/commands/hist.rb
+++ b/lib/pry/commands/hist.rb
@@ -36,13 +36,9 @@ class Pry
def process
@history = find_history
- if opts.present?(:show)
- @history = @history.between(opts[:show])
- end
+ @history = @history.between(opts[:show]) if opts.present?(:show)
- if opts.present?(:grep)
- @history = @history.grep(opts[:grep])
- end
+ @history = @history.grep(opts[:grep]) if opts.present?(:grep)
@history =
if opts.present?(:head)
@@ -75,9 +71,7 @@ class Pry
private
def process_display
- unless opts.present?(:'no-numbers')
- @history = @history.with_line_numbers
- end
+ @history = @history.with_line_numbers unless opts.present?(:'no-numbers')
_pry_.pager.open do |pager|
@history.print_to_output(pager, true)
@@ -89,9 +83,7 @@ class Pry
when Range
@history = @history.between(opts[:save])
- unless args.first
- raise CommandError, "Must provide a file name."
- end
+ raise CommandError, "Must provide a file name." unless args.first
file_name = File.expand_path(args.first)
when String
diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb
index 43dd8e7a..d19ef248 100644
--- a/lib/pry/commands/ls.rb
+++ b/lib/pry/commands/ls.rb
@@ -60,12 +60,8 @@ class Pry
"#{' ' * 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
- if Object.respond_to?(:deprecate_constant)
- opt.on :d, :dconstants, "Show deprecated constants"
- end
- if Helpers::Platform.jruby?
- opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
- end
+ opt.on :d, :dconstants, "Show deprecated constants" if Object.respond_to?(:deprecate_constant)
+ opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)" if Helpers::Platform.jruby?
end
# Exclude -q, -v and --grep because they,
diff --git a/lib/pry/commands/ls/methods_helper.rb b/lib/pry/commands/ls/methods_helper.rb
index 14ec0919..d8270ba6 100644
--- a/lib/pry/commands/ls/methods_helper.rb
+++ b/lib/pry/commands/ls/methods_helper.rb
@@ -16,9 +16,7 @@ class Pry
Pry::Method.all_from_obj(@interrogatee)
end
- if Pry::Helpers::Platform.jruby? && !@jruby_switch
- methods = trim_jruby_aliases(methods)
- end
+ methods = trim_jruby_aliases(methods) if Pry::Helpers::Platform.jruby? && !@jruby_switch
methods.select { |method| @ppp_switch || method.visibility == :public }
end
diff --git a/lib/pry/commands/play.rb b/lib/pry/commands/play.rb
index c74906ef..e05c1b71 100644
--- a/lib/pry/commands/play.rb
+++ b/lib/pry/commands/play.rb
@@ -49,9 +49,7 @@ class Pry
end
def show_input
- if opts.present?(:print) || !Pry::Code.complete_expression?(eval_string)
- run "show-input"
- end
+ run "show-input" if opts.present?(:print) || !Pry::Code.complete_expression?(eval_string)
end
def content_after_options
diff --git a/lib/pry/commands/reload_code.rb b/lib/pry/commands/reload_code.rb
index 1dba1a22..2f70f92d 100644
--- a/lib/pry/commands/reload_code.rb
+++ b/lib/pry/commands/reload_code.rb
@@ -38,9 +38,7 @@ class Pry
end
def reload_current_file
- if !File.exist?(current_file)
- raise CommandError, "Current file: #{current_file} cannot be found on disk!"
- end
+ raise CommandError, "Current file: #{current_file} cannot be found on disk!" if !File.exist?(current_file)
load current_file
output.puts "The current file: #{current_file} was reloaded!"
diff --git a/lib/pry/commands/ri.rb b/lib/pry/commands/ri.rb
index c2abd046..8e333f0a 100644
--- a/lib/pry/commands/ri.rb
+++ b/lib/pry/commands/ri.rb
@@ -15,9 +15,7 @@ class Pry
BANNER
def process(spec)
- unless spec
- return output.puts "Please provide a class, module, or method name (e.g: ri Array#push)"
- end
+ return output.puts "Please provide a class, module, or method name (e.g: ri Array#push)" unless spec
# Lazily load RI
require 'rdoc/ri/driver'
diff --git a/lib/pry/commands/shell_command.rb b/lib/pry/commands/shell_command.rb
index c06efab2..1b7d2c38 100644
--- a/lib/pry/commands/shell_command.rb
+++ b/lib/pry/commands/shell_command.rb
@@ -57,9 +57,7 @@ class Pry
return if !(dest && cd_path_exists?) || special_case_path?(dest)
cd_path_env.split(File::PATH_SEPARATOR).each do |path|
- if File.directory?(path) && path.split(File::SEPARATOR).last == dest
- return path
- end
+ return path if File.directory?(path) && path.split(File::SEPARATOR).last == dest
end
return nil
diff --git a/lib/pry/commands/show_info.rb b/lib/pry/commands/show_info.rb
index beca4d97..43573e40 100644
--- a/lib/pry/commands/show_info.rb
+++ b/lib/pry/commands/show_info.rb
@@ -109,9 +109,7 @@ class Pry
h << "\n#{bold('Number of lines:')} " << "#{content.lines.count}\n\n"
h << bold('** Warning:') << " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
- if content.lines.none?
- h << bold('** Warning:') << " Cannot find code for '#{code_object.name}' (source_location is nil)"
- end
+ h << bold('** Warning:') << " Cannot find code for '#{code_object.name}' (source_location is nil)" if content.lines.none?
h
end
diff --git a/lib/pry/commands/watch_expression.rb b/lib/pry/commands/watch_expression.rb
index 5a2fd32a..a08ea731 100644
--- a/lib/pry/commands/watch_expression.rb
+++ b/lib/pry/commands/watch_expression.rb
@@ -80,9 +80,7 @@ class Pry
def eval_and_print_changed(output)
expressions.each do |expr|
expr.eval!
- if expr.changed?
- output.puts "#{blue "watch"}: #{expr}"
- end
+ output.puts "#{blue "watch"}: #{expr}" if expr.changed?
end
end
diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb
index 78ca3bbc..f6c3a841 100644
--- a/lib/pry/commands/whereami.rb
+++ b/lib/pry/commands/whereami.rb
@@ -86,9 +86,7 @@ class Pry
end
def process
- if bad_option_combination?
- raise CommandError, "Only one of -m, -c, -f, and LINES may be specified."
- end
+ raise CommandError, "Only one of -m, -c, -f, and LINES may be specified." if bad_option_combination?
if nothing_to_do?
return
@@ -152,9 +150,7 @@ class Pry
def method_code
return @method_code if @method_code
- if valid_method?
- @method_code = Pry::Code.from_method(@method)
- end
+ @method_code = Pry::Code.from_method(@method) if valid_method?
end
# This either returns the `target_self`
diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb
index 088c6c5b..155fc7e9 100644
--- a/lib/pry/config/behavior.rb
+++ b/lib/pry/config/behavior.rb
@@ -164,9 +164,7 @@ class Pry
#
def []=(key, value)
key = key.to_s
- if @reserved_keys.include?(key)
- raise ReservedKeyError, "It is not possible to use '#{key}' as a key name, please choose a different key name."
- end
+ raise ReservedKeyError, "It is not possible to use '#{key}' as a key name, please choose a different key name." if @reserved_keys.include?(key)
__push(key, value)
end
diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb
index 209ae49a..7c766918 100644
--- a/lib/pry/helpers/command_helpers.rb
+++ b/lib/pry/helpers/command_helpers.rb
@@ -23,9 +23,7 @@ class Pry
def get_method_or_raise(name, target, opts = {}, omit_help = false)
meth = Pry::Method.from_str(name, target, opts)
- if name && !meth
- command_error("The method '#{name}' could not be found.", omit_help, MethodNotFound)
- end
+ command_error("The method '#{name}' could not be found.", omit_help, MethodNotFound) if name && !meth
(opts[:super] || 0).times do
if meth.super
@@ -35,9 +33,7 @@ class Pry
end
end
- if !meth || (!name && internal_binding?(target))
- command_error("No method name given, and context is not a method.", omit_help, MethodNotFound)
- end
+ command_error("No method name given, and context is not a method.", omit_help, MethodNotFound) if !meth || (!name && internal_binding?(target))
set_file_and_dir_locals(meth.source_file)
meth
diff --git a/lib/pry/history.rb b/lib/pry/history.rb
index 79b5bd16..b05815cc 100644
--- a/lib/pry/history.rb
+++ b/lib/pry/history.rb
@@ -41,9 +41,7 @@ class Pry
return line if line == last_line
@history << line
- if !should_ignore?(line) && Pry.config.history.should_save
- @saver.call(line)
- end
+ @saver.call(line) if !should_ignore?(line) && Pry.config.history.should_save
line
end
@@ -97,9 +95,7 @@ class Pry
def read_from_file
path = history_file_path
- if File.exist?(path)
- File.foreach(path) { |line| yield(line) }
- end
+ File.foreach(path) { |line| yield(line) } if File.exist?(path)
rescue SystemCallError => error
warn "Unable to read history file: #{error.message}"
end
@@ -114,9 +110,7 @@ class Pry
if defined?(@history_file)
@history_file
else
- unless File.exist?(history_file_path)
- FileUtils.mkdir_p(File.dirname(history_file_path))
- end
+ FileUtils.mkdir_p(File.dirname(history_file_path)) unless File.exist?(history_file_path)
@history_file = File.open(history_file_path, 'a', 0600).tap do |file|
file.sync = true
end
diff --git a/lib/pry/hooks.rb b/lib/pry/hooks.rb
index 6f5b3fe0..5958b7d4 100644
--- a/lib/pry/hooks.rb
+++ b/lib/pry/hooks.rb
@@ -70,13 +70,9 @@ class Pry
# do not allow duplicates, but allow multiple `nil` hooks
# (anonymous hooks)
- if hook_exists?(event_name, hook_name) && !hook_name.nil?
- raise ArgumentError, "Hook with name '#{hook_name}' already defined!"
- end
+ raise ArgumentError, "Hook with name '#{hook_name}' already defined!" if hook_exists?(event_name, hook_name) && !hook_name.nil?
- if !block && !callable
- raise ArgumentError, "Must provide a block or callable."
- end
+ raise ArgumentError, "Must provide a block or callable." if !block && !callable
# ensure we only have one anonymous hook
@hooks[event_name].delete_if { |h, _k| h.nil? } if hook_name.nil?
diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb
index a3f1b9ef..b8812ae9 100644
--- a/lib/pry/indent.rb
+++ b/lib/pry/indent.rb
@@ -353,9 +353,7 @@ class Pry
# @param [String] token a token from Coderay
# @param [Symbol] kind the kind of that token
def track_module_nesting_end(token, kind = :keyword)
- if kind == :keyword && (token == "class" || token == "module")
- @module_nesting.pop
- end
+ @module_nesting.pop if kind == :keyword && (token == "class" || token == "module")
end
# Return a list of strings which can be used to re-construct the Module.nesting at
diff --git a/lib/pry/input_completer.rb b/lib/pry/input_completer.rb
index 7c0df7b5..05cd5034 100644
--- a/lib/pry/input_completer.rb
+++ b/lib/pry/input_completer.rb
@@ -176,9 +176,7 @@ class Pry
# jruby doesn't always provide #instance_methods() on each
# object.
- if m.respond_to?(:instance_methods)
- candidates.merge m.instance_methods(false).collect(&:to_s)
- end
+ candidates.merge m.instance_methods(false).collect(&:to_s) if m.respond_to?(:instance_methods)
end
end
select_message(path, receiver, message, candidates.sort)
@@ -195,9 +193,7 @@ class Pry
bind
).collect(&:to_s)
- if eval("respond_to?(:class_variables)", bind)
- candidates += eval("class_variables", bind).collect(&:to_s)
- end
+ candidates += eval("class_variables", bind).collect(&:to_s) if eval("respond_to?(:class_variables)", bind)
candidates = (candidates | ReservedWords | custom_completions).grep(/^#{Regexp.quote(input)}/)
candidates.collect(&path)
end
diff --git a/lib/pry/method.rb b/lib/pry/method.rb
index c46deef3..65614864 100644
--- a/lib/pry/method.rb
+++ b/lib/pry/method.rb
@@ -478,9 +478,7 @@ class Pry
Pry::MethodInfo.info_for(@method) || raise(CommandError, "Cannot locate this method: #{name}. (source_location returns nil)")
else
fail_msg = "Cannot locate this method: #{name}."
- if Helpers::Platform.mri?
- fail_msg += " Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.\n"
- end
+ fail_msg += " Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.\n" if Helpers::Platform.mri?
raise CommandError, fail_msg
end
end
@@ -508,9 +506,7 @@ class Pry
tokens = CodeRay.scan(first_ln, :ruby)
tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens)
tokens.each_cons(2) do |t1, t2|
- if t2.last == :method || t2.last == :ident && t1 == [".", :operator]
- return t2.first
- end
+ return t2.first if t2.last == :method || t2.last == :ident && t1 == [".", :operator]
end
nil
@@ -518,9 +514,7 @@ class Pry
def c_source
info = pry_doc_info
- if info && info.source
- strip_comments_from_c_code(info.source)
- end
+ strip_comments_from_c_code(info.source) if info && info.source
end
def ruby_source
diff --git a/lib/pry/method/weird_method_locator.rb b/lib/pry/method/weird_method_locator.rb
index 6bf3c87f..a4167b5d 100644
--- a/lib/pry/method/weird_method_locator.rb
+++ b/lib/pry/method/weird_method_locator.rb
@@ -124,9 +124,7 @@ class Pry
# superclass method.
def find_method_in_superclass
guess = method
- if skip_superclass_search?
- return guess
- end
+ return guess if skip_superclass_search?
while guess
# needs rescue if this is a Disowned method or a C method or something...
diff --git a/lib/pry/pager.rb b/lib/pry/pager.rb
index 48e60dfa..cf18e2a9 100644
--- a/lib/pry/pager.rb
+++ b/lib/pry/pager.rb
@@ -130,9 +130,7 @@ class Pry
# Default to less, and make sure less is being passed the correct
# options
- if pager.strip.empty? || pager =~ /^less\b/
- pager = "less -R -F -X"
- end
+ pager = "less -R -F -X" if pager.strip.empty? || pager =~ /^less\b/
pager
end
@@ -172,9 +170,7 @@ class Pry
@tracker.record str
@buffer << str
- if @tracker.page?
- write_to_pager @buffer
- end
+ write_to_pager @buffer if @tracker.page?
end
rescue Errno::EPIPE
raise StopPaging
diff --git a/lib/pry/plugins.rb b/lib/pry/plugins.rb
index b415db7a..6d71432b 100644
--- a/lib/pry/plugins.rb
+++ b/lib/pry/plugins.rb
@@ -68,9 +68,7 @@ class Pry
def supported?
pry_version = Gem::Version.new(VERSION)
spec.dependencies.each do |dependency|
- if dependency.name == "pry"
- return dependency.requirement.satisfied_by?(pry_version)
- end
+ return dependency.requirement.satisfied_by?(pry_version) if dependency.name == "pry"
end
true
end
diff --git a/lib/pry/prompt.rb b/lib/pry/prompt.rb
index 232fd61c..6b2ebcb5 100644
--- a/lib/pry/prompt.rb
+++ b/lib/pry/prompt.rb
@@ -84,13 +84,9 @@ class Pry
def add(name, description = '', separators = %w[> *])
name = name.to_s
- unless separators.size == 2
- raise ArgumentError, "separators size must be 2, given #{separators.size}"
- end
+ raise ArgumentError, "separators size must be 2, given #{separators.size}" unless separators.size == 2
- if @prompts.key?(name)
- raise ArgumentError, "the '#{name}' prompt was already added"
- end
+ raise ArgumentError, "the '#{name}' prompt was already added" if @prompts.key?(name)
@prompts[name] = new(
name,
diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb
index 7161a4ea..7a5d9928 100644
--- a/lib/pry/pry_class.rb
+++ b/lib/pry/pry_class.rb
@@ -173,9 +173,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
# Pry.start(Object.new, :input => MyInput.new)
def self.start(target = nil, options = {})
return if ENV['DISABLE_PRY']
- if ENV['FAIL_PRY']
- raise 'You have FAIL_PRY set to true, which results in Pry calls failing'
- end
+ raise 'You have FAIL_PRY set to true, which results in Pry calls failing' if ENV['FAIL_PRY']
options = options.to_hash
@@ -194,9 +192,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
options[:backtrace] = caller
# If Pry was started via `binding.pry`, elide that from the backtrace
- if options[:backtrace].first =~ /pry.*core_extensions.*pry/
- options[:backtrace].shift
- end
+ options[:backtrace].shift if options[:backtrace].first =~ /pry.*core_extensions.*pry/
end
driver = options[:driver] || Pry::REPL
diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb
index 284224fa..e7712221 100644
--- a/lib/pry/pry_instance.rb
+++ b/lib/pry/pry_instance.rb
@@ -300,9 +300,7 @@ class Pry
end
if complete_expr
- if @eval_string =~ /;\Z/ || @eval_string.empty? || @eval_string =~ /\A *#.*\n\z/
- @suppress_output = true
- end
+ @suppress_output = true if @eval_string =~ /;\Z/ || @eval_string.empty? || @eval_string =~ /\A *#.*\n\z/
# A bug in jruby makes java.lang.Exception not rescued by
# `rescue Pry::RescuableException` clause.
@@ -316,9 +314,7 @@ class Pry
# This workaround has a side effect: java exceptions specified
# in `Pry.config.unrescued_exceptions` are ignored.
jruby_exceptions = []
- if Helpers::Platform.jruby?
- jruby_exceptions << Java::JavaLang::Exception
- end
+ jruby_exceptions << Java::JavaLang::Exception if Helpers::Platform.jruby?
begin
# Reset eval string, in case we're evaluating Ruby that does something
@@ -331,9 +327,7 @@ class Pry
# Eliminate following warning:
# warning: singleton on non-persistent Java type X
# (http://wiki.jruby.org/Persistence)
- if Helpers::Platform.jruby? && e.class.respond_to?('__persistent__')
- e.class.__persistent__ = true
- end
+ e.class.__persistent__ = true if Helpers::Platform.jruby? && e.class.respond_to?('__persistent__')
self.last_exception = e
result = e
end
diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb
index 0b4d7480..846dcbc9 100644
--- a/lib/pry/repl.rb
+++ b/lib/pry/repl.rb
@@ -23,9 +23,7 @@ class Pry
@readline_output = nil
- if options[:target]
- @pry.push_binding options[:target]
- end
+ @pry.push_binding options[:target] if options[:target]
end
# Start the read-eval-print loop.
@@ -151,9 +149,7 @@ class Pry
puts "Error: #{e.message}"
output.puts e.backtrace
exception_count += 1
- if exception_count < 5
- retry
- end
+ retry if exception_count < 5
puts "FATAL: Pry failed to get user input using `#{input}`."
puts "To fix this you may be able to pass input and output file " \
"descriptors to pry directly. e.g."
@@ -227,9 +223,7 @@ class Pry
def set_readline_output
return if @readline_output
- if piping?
- @readline_output = (Readline.output = Pry.config.output)
- end
+ @readline_output = (Readline.output = Pry.config.output) if piping?
end
# Calculates correct overhang for current line. Supports vi Readline
@@ -246,9 +240,7 @@ class Pry
begin
# rb-readline doesn't support this method:
# https://github.com/ConnorAtherton/rb-readline/issues/152
- if Readline.vi_editing_mode?
- overhang += current_prompt.length - indented_val.length
- end
+ overhang += current_prompt.length - indented_val.length if Readline.vi_editing_mode?
rescue NotImplementedError
# VI editing mode is unsupported on JRuby.
# https://github.com/pry/pry/issues/1840
diff --git a/lib/pry/slop.rb b/lib/pry/slop.rb
index 00661654..56a36a5c 100644
--- a/lib/pry/slop.rb
+++ b/lib/pry/slop.rb
@@ -233,13 +233,9 @@ class Pry
"Missing required option(s): #{missing_options.map(&:key).join(', ')}"
end
- if @unknown_options.any?
- raise InvalidOptionError, "Unknown options #{@unknown_options.join(', ')}"
- end
+ raise InvalidOptionError, "Unknown options #{@unknown_options.join(', ')}" if @unknown_options.any?
- if @triggered_options.empty? && @callbacks[:no_options]
- @callbacks[:no_options].each { |cb| cb.call(self) }
- end
+ @callbacks[:no_options].each { |cb| cb.call(self) } if @triggered_options.empty? && @callbacks[:no_options]
@runner.call(self, items) if @runner.respond_to?(:call)
@@ -280,9 +276,7 @@ class Pry
# include_commands - If true, merge options from all sub-commands.
def to_hash(include_commands = false)
hash = Hash[options.map { |opt| [opt.key.to_sym, opt.value] }]
- if include_commands
- @commands.each { |cmd, opts| hash.merge!(cmd.to_sym => opts.to_hash) }
- end
+ @commands.each { |cmd, opts| hash.merge!(cmd.to_sym => opts.to_hash) } if include_commands
hash
end
alias to_h to_hash
@@ -310,9 +304,7 @@ class Pry
# end
def run(callable = nil, &block)
@runner = callable || block
- unless @runner.respond_to?(:call)
- raise ArgumentError, "You must specify a callable object or a block to #run"
- end
+ raise ArgumentError, "You must specify a callable object or a block to #run" unless @runner.respond_to?(:call)
end
# Check for an options presence.
@@ -476,9 +468,7 @@ class Pry
if option.expects_argument?
argument ||= items.at(index + 1)
- if !argument || argument =~ /\A--?[a-zA-Z][a-zA-Z0-9_-]*\z/
- raise MissingArgumentError, "#{option.key} expects an argument"
- end
+ raise MissingArgumentError, "#{option.key} expects an argument" if !argument || argument =~ /\A--?[a-zA-Z][a-zA-Z0-9_-]*\z/
execute_option(option, argument, index, item)
elsif option.accepts_optional_argument?
@@ -511,9 +501,7 @@ class Pry
# Returns nothing.
def execute_option(option, argument, index, item = nil)
if !option
- if config[:multiple_switches] && strict?
- raise InvalidOptionError, "Unknown option -#{item}"
- end
+ raise InvalidOptionError, "Unknown option -#{item}" if config[:multiple_switches] && strict?
return
end
@@ -527,9 +515,7 @@ class Pry
option.value = option.count > 0
end
- if option.match? && !argument.match(option.config[:match])
- raise InvalidArgumentError, "#{argument} is an invalid argument"
- end
+ raise InvalidArgumentError, "#{argument} is an invalid argument" if option.match? && !argument.match(option.config[:match])
option.call(option.value)
end
diff --git a/lib/pry/slop/commands.rb b/lib/pry/slop/commands.rb
index 9e93941d..d406b750 100644
--- a/lib/pry/slop/commands.rb
+++ b/lib/pry/slop/commands.rb
@@ -143,9 +143,7 @@ class Pry
if (opts = commands['default'])
opts.parse! items
else
- if config[:strict] && items[0]
- raise InvalidCommandError, "Unknown command `#{items[0]}`"
- end
+ raise InvalidCommandError, "Unknown command `#{items[0]}`" if config[:strict] && items[0]
end
execute_global_opts! items
end
@@ -162,12 +160,8 @@ class Pry
defaults = commands.delete('default')
globals = commands.delete('global')
helps = commands.reject { |_, v| v.options.none? }
- if globals && globals.options.any?
- helps['Global options'] = globals.to_s
- end
- if defaults && defaults.options.any?
- helps['Other options'] = defaults.to_s
- end
+ helps['Global options'] = globals.to_s if globals && globals.options.any?
+ helps['Other options'] = defaults.to_s if defaults && defaults.options.any?
banner = @banner ? "#{@banner}\n" : ""
banner + helps.map { |key, opts| " #{key}\n#{opts}" }.join("\n\n")
end
diff --git a/lib/pry/slop/option.rb b/lib/pry/slop/option.rb
index a94847dc..476f161e 100644
--- a/lib/pry/slop/option.rb
+++ b/lib/pry/slop/option.rb
@@ -49,15 +49,11 @@ class Pry
count: proc { @count }
}
- if long && long.size > @slop.config[:longest_flag]
- @slop.config[:longest_flag] = long.size
- end
+ @slop.config[:longest_flag] = long.size if long && long.size > @slop.config[:longest_flag]
@config.each_key do |key|
predicate = :"#{key}?"
- unless self.class.method_defined? predicate
- self.class.__send__(:define_method, predicate) { !!@config[key] }
- end
+ self.class.__send__(:define_method, predicate) { !!@config[key] } unless self.class.method_defined? predicate
end
end
@@ -92,9 +88,7 @@ class Pry
if config[:as].to_s.casecmp('array') == 0
@value ||= []
- if new_value.respond_to?(:split)
- @value.concat new_value.split(config[:delimiter], config[:limit])
- end
+ @value.concat new_value.split(config[:delimiter], config[:limit]) if new_value.respond_to?(:split)
else
@value = new_value
end
@@ -106,9 +100,7 @@ class Pry
def value
value = @value.nil? ? config[:default] : @value
- if [true, false, nil].include?(value) && config[:as].to_s != 'count'
- return value
- end
+ return value if [true, false, nil].include?(value) && config[:as].to_s != 'count'
type = config[:as]
if type.respond_to?(:call)
diff --git a/lib/pry/terminal.rb b/lib/pry/terminal.rb
index 737895f7..c2e80e56 100644
--- a/lib/pry/terminal.rb
+++ b/lib/pry/terminal.rb
@@ -6,9 +6,7 @@ class Pry
# If the window size cannot be determined, return nil.
def screen_size
rows, cols = actual_screen_size
- if rows.to_i != 0 && cols.to_i != 0
- [rows.to_i, cols.to_i]
- end
+ [rows.to_i, cols.to_i] if rows.to_i != 0 && cols.to_i != 0
end
# Return a screen size or a default if that fails.
@@ -45,9 +43,7 @@ class Pry
require 'io/console'
begin
- if $stdout.respond_to?(:tty?) && $stdout.tty? && $stdout.respond_to?(:winsize)
- $stdout.winsize
- end
+ $stdout.winsize if $stdout.respond_to?(:tty?) && $stdout.tty? && $stdout.respond_to?(:winsize)
rescue Errno::EOPNOTSUPP
# $stdout is probably a socket, which doesn't support #winsize.
end
diff --git a/lib/pry/testable/evalable.rb b/lib/pry/testable/evalable.rb
index 78f43824..d43adb4a 100644
--- a/lib/pry/testable/evalable.rb
+++ b/lib/pry/testable/evalable.rb
@@ -2,9 +2,7 @@ class Pry
module Testable
module Evalable
def pry_tester(*args, &block)
- if args.length == 0 || args[0].is_a?(Hash)
- args.unshift(Pry.toplevel_binding)
- end
+ args.unshift(Pry.toplevel_binding) if args.length == 0 || args[0].is_a?(Hash)
Pry::Testable::PryTester.new(*args).tap do |t|
t.singleton_class.class_eval(&block) if block
end
diff --git a/lib/pry/testable/pry_tester.rb b/lib/pry/testable/pry_tester.rb
index 6572c2e8..fa92e9ff 100644
--- a/lib/pry/testable/pry_tester.rb
+++ b/lib/pry/testable/pry_tester.rb
@@ -18,9 +18,7 @@ class Pry
strs.flatten.each do |str|
# Check for space prefix. See #1369.
- if str !~ /^\s\S/
- str = "#{str.strip}\n"
- end
+ str = "#{str.strip}\n" if str !~ /^\s\S/
@history.push str if @history
result =
diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb
index bafb051e..0d9a579d 100644
--- a/lib/pry/wrapped_module.rb
+++ b/lib/pry/wrapped_module.rb
@@ -27,9 +27,7 @@ class Pry
# @example
# Pry::WrappedModule.from_str("Pry::Code")
def self.from_str(mod_name, target = TOPLEVEL_BINDING)
- if safe_to_evaluate?(mod_name, target)
- Pry::WrappedModule.new(target.eval(mod_name))
- end
+ Pry::WrappedModule.new(target.eval(mod_name)) if safe_to_evaluate?(mod_name, target)
rescue RescuableException
nil
end
diff --git a/spec/commands/show_doc_spec.rb b/spec/commands/show_doc_spec.rb
index 9e63040e..4153f3a6 100644
--- a/spec/commands/show_doc_spec.rb
+++ b/spec/commands/show_doc_spec.rb
@@ -13,9 +13,7 @@ describe "show-doc" do
end
after do
- if Symbol.method_defined? :call
- Symbol.class_eval { undef :call }
- end
+ Symbol.class_eval { undef :call } if Symbol.method_defined? :call
end
it "emits a deprecation warning" do
diff --git a/spec/commands/wtf_spec.rb b/spec/commands/wtf_spec.rb
index 118046e7..7c8268f3 100644
--- a/spec/commands/wtf_spec.rb
+++ b/spec/commands/wtf_spec.rb
@@ -12,9 +12,7 @@ describe "wtf?!" do
end
it "unwinds nested exceptions" do
- if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0.0')
- skip('Exception#cause is not supported')
- end
+ skip('Exception#cause is not supported') if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0.0')
begin
begin
diff --git a/spec/spec_helpers/repl_tester.rb b/spec/spec_helpers/repl_tester.rb
index e353ca99..9cb34c22 100644
--- a/spec/spec_helpers/repl_tester.rb
+++ b/spec/spec_helpers/repl_tester.rb
@@ -36,9 +36,7 @@ class ReplTester
instance.ensure_exit
end
ensure
- if instance && instance.thread && instance.thread.alive?
- instance.thread.kill
- end
+ instance.thread.kill if instance && instance.thread && instance.thread.alive?
end
attr_accessor :thread, :mailbox, :last_prompt