pry 0.11.3 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry/cli.rb +17 -24
  7. data/lib/pry/code/code_file.rb +5 -4
  8. data/lib/pry/code/code_range.rb +3 -3
  9. data/lib/pry/code/loc.rb +14 -8
  10. data/lib/pry/code.rb +6 -6
  11. data/lib/pry/code_object.rb +4 -4
  12. data/lib/pry/color_printer.rb +1 -0
  13. data/lib/pry/command.rb +36 -29
  14. data/lib/pry/command_set.rb +17 -52
  15. data/lib/pry/commands/amend_line.rb +3 -4
  16. data/lib/pry/commands/bang.rb +1 -1
  17. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  18. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  19. data/lib/pry/commands/cat.rb +7 -6
  20. data/lib/pry/commands/change_prompt.rb +29 -9
  21. data/lib/pry/commands/clear_screen.rb +14 -0
  22. data/lib/pry/commands/code_collector.rb +9 -9
  23. data/lib/pry/commands/easter_eggs.rb +3 -3
  24. data/lib/pry/commands/edit.rb +8 -7
  25. data/lib/pry/commands/exit.rb +2 -1
  26. data/lib/pry/commands/find_method.rb +11 -13
  27. data/lib/pry/commands/gem_cd.rb +1 -1
  28. data/lib/pry/commands/gem_install.rb +2 -2
  29. data/lib/pry/commands/gem_list.rb +2 -2
  30. data/lib/pry/commands/gem_open.rb +1 -1
  31. data/lib/pry/commands/gem_search.rb +2 -2
  32. data/lib/pry/commands/gem_stats.rb +83 -0
  33. data/lib/pry/commands/gist.rb +7 -6
  34. data/lib/pry/commands/help.rb +3 -3
  35. data/lib/pry/commands/hist.rb +9 -8
  36. data/lib/pry/commands/import_set.rb +2 -1
  37. data/lib/pry/commands/install_command.rb +7 -6
  38. data/lib/pry/commands/list_inspectors.rb +2 -2
  39. data/lib/pry/commands/ls/constants.rb +4 -4
  40. data/lib/pry/commands/ls/formatter.rb +3 -2
  41. data/lib/pry/commands/ls/globals.rb +0 -2
  42. data/lib/pry/commands/ls/grep.rb +0 -2
  43. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  44. data/lib/pry/commands/ls/local_names.rb +0 -2
  45. data/lib/pry/commands/ls/local_vars.rb +0 -2
  46. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  47. data/lib/pry/commands/ls/methods.rb +0 -3
  48. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  49. data/lib/pry/commands/ls/self_methods.rb +0 -1
  50. data/lib/pry/commands/ls.rb +27 -30
  51. data/lib/pry/commands/play.rb +1 -2
  52. data/lib/pry/commands/pry_backtrace.rb +1 -1
  53. data/lib/pry/commands/raise_up.rb +2 -1
  54. data/lib/pry/commands/ri.rb +5 -4
  55. data/lib/pry/commands/shell_command.rb +3 -2
  56. data/lib/pry/commands/shell_mode.rb +6 -6
  57. data/lib/pry/commands/show_doc.rb +5 -7
  58. data/lib/pry/commands/show_info.rb +25 -18
  59. data/lib/pry/commands/show_source.rb +5 -2
  60. data/lib/pry/commands/stat.rb +1 -1
  61. data/lib/pry/commands/watch_expression.rb +9 -7
  62. data/lib/pry/commands/whereami.rb +4 -4
  63. data/lib/pry/commands/wtf.rb +15 -2
  64. data/lib/pry/config/behavior.rb +229 -205
  65. data/lib/pry/config/convenience.rb +24 -21
  66. data/lib/pry/config/default.rb +153 -143
  67. data/lib/pry/config/memoization.rb +41 -37
  68. data/lib/pry/config.rb +33 -9
  69. data/lib/pry/core_extensions.rb +4 -3
  70. data/lib/pry/editor.rb +5 -12
  71. data/lib/pry/exceptions.rb +0 -2
  72. data/lib/pry/helpers/base_helpers.rb +133 -4
  73. data/lib/pry/helpers/command_helpers.rb +5 -4
  74. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  75. data/lib/pry/helpers/options_helpers.rb +5 -5
  76. data/lib/pry/helpers/platform.rb +58 -0
  77. data/lib/pry/helpers/table.rb +20 -15
  78. data/lib/pry/helpers/text.rb +3 -4
  79. data/lib/pry/helpers.rb +1 -0
  80. data/lib/pry/history.rb +21 -8
  81. data/lib/pry/hooks.rb +3 -3
  82. data/lib/pry/indent.rb +15 -17
  83. data/lib/pry/input_completer.rb +12 -7
  84. data/lib/pry/input_lock.rb +0 -2
  85. data/lib/pry/last_exception.rb +1 -1
  86. data/lib/pry/method/disowned.rb +2 -1
  87. data/lib/pry/method/patcher.rb +2 -2
  88. data/lib/pry/method/weird_method_locator.rb +7 -8
  89. data/lib/pry/method.rb +37 -31
  90. data/lib/pry/object_path.rb +5 -4
  91. data/lib/pry/output.rb +3 -2
  92. data/lib/pry/pager.rb +194 -186
  93. data/lib/pry/platform.rb +79 -81
  94. data/lib/pry/plugins.rb +7 -3
  95. data/lib/pry/prompt.rb +144 -25
  96. data/lib/pry/pry_class.rb +53 -29
  97. data/lib/pry/pry_instance.rb +88 -55
  98. data/lib/pry/repl.rb +33 -4
  99. data/lib/pry/repl_file_loader.rb +1 -2
  100. data/lib/pry/ring.rb +84 -0
  101. data/lib/pry/rubygem.rb +6 -6
  102. data/lib/pry/slop/commands.rb +3 -4
  103. data/lib/pry/slop/option.rb +19 -21
  104. data/lib/pry/slop.rb +17 -17
  105. data/lib/pry/terminal.rb +2 -1
  106. data/lib/pry/testable/mockable.rb +2 -2
  107. data/lib/pry/testable/pry_tester.rb +1 -1
  108. data/lib/pry/testable/utility.rb +2 -2
  109. data/lib/pry/testable/variables.rb +1 -1
  110. data/lib/pry/version.rb +1 -1
  111. data/lib/pry/wrapped_module/candidate.rb +2 -2
  112. data/lib/pry/wrapped_module.rb +15 -15
  113. data/lib/pry.rb +17 -47
  114. metadata +8 -20
  115. data/lib/pry/commands/list_prompts.rb +0 -35
  116. data/lib/pry/commands/simple_prompt.rb +0 -22
  117. data/lib/pry/history_array.rb +0 -121
  118. data/lib/pry/rbx_path.rb +0 -22
@@ -2,31 +2,30 @@ require 'pry/commands/ls/ls_entity'
2
2
  class Pry
3
3
  class Command::Ls < Pry::ClassCommand
4
4
  DEFAULT_OPTIONS = {
5
- :heading_color => :bright_blue,
6
- :public_method_color => :default,
7
- :private_method_color => :blue,
8
- :protected_method_color => :blue,
9
- :method_missing_color => :bright_red,
10
- :local_var_color => :yellow,
11
- :pry_var_color => :default, # e.g. _, _pry_, _file_
12
- :instance_var_color => :blue, # e.g. @foo
13
- :class_var_color => :bright_blue, # e.g. @@foo
14
- :global_var_color => :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
15
- :builtin_global_color => :cyan, # e.g. $stdin, $-w, $PID
16
- :pseudo_global_color => :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
17
- :constant_color => :default, # e.g. VERSION, ARGF
18
- :class_constant_color => :blue, # e.g. Object, Kernel
19
- :exception_constant_color => :magenta, # e.g. Exception, RuntimeError
20
- :unloaded_constant_color => :yellow, # Any constant that is still in .autoload? state
21
- :separator => " ",
22
- :ceiling => [Object, Module, Class]
5
+ heading_color: :bright_blue,
6
+ public_method_color: :default,
7
+ private_method_color: :blue,
8
+ protected_method_color: :blue,
9
+ method_missing_color: :bright_red,
10
+ local_var_color: :yellow,
11
+ pry_var_color: :default, # e.g. _, _pry_, _file_
12
+ instance_var_color: :blue, # e.g. @foo
13
+ class_var_color: :bright_blue, # e.g. @@foo
14
+ global_var_color: :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
15
+ builtin_global_color: :cyan, # e.g. $stdin, $-w, $PID
16
+ pseudo_global_color: :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
17
+ constant_color: :default, # e.g. VERSION, ARGF
18
+ class_constant_color: :blue, # e.g. Object, Kernel
19
+ exception_constant_color: :magenta, # e.g. Exception, RuntimeError
20
+ unloaded_constant_color: :yellow, # Any constant that is still in .autoload? state
21
+ separator: " ",
22
+ ceiling: [Object, Module, Class]
23
23
  }
24
24
 
25
-
26
25
  match 'ls'
27
26
  group 'Context'
28
27
  description 'Show the list of vars and methods in the current scope.'
29
- command_options :shellwords => false, :interpolate => false
28
+ command_options shellwords: false, interpolate: false
30
29
 
31
30
  banner <<-'BANNER'
32
31
  Usage: ls [-m|-M|-p|-pM] [-q|-v] [-c|-i] [Object]
@@ -48,9 +47,8 @@ class Pry
48
47
  Also check out `find-method` command (run `help find-method`).
49
48
  BANNER
50
49
 
51
-
52
50
  def options(opt)
53
- opt.on :m, :methods, "Show public methods defined on the Object"
51
+ opt.on :m, :methods, "Show public methods defined on the Object"
54
52
  opt.on :M, "instance-methods", "Show public methods defined in a Module or Class"
55
53
  opt.on :p, :ppp, "Show public, protected (in yellow) and private (in green) methods"
56
54
  opt.on :q, :quiet, "Show only methods defined on object.singleton_class and object.class"
@@ -60,11 +58,11 @@ class Pry
60
58
  opt.on :c, :constants, "Show constants, highlighting classes (in blue), and exceptions (in purple).\n" <<
61
59
  " " * 32 << "Constants that are pending autoload? are also shown (in yellow)"
62
60
  opt.on :i, :ivars, "Show instance variables (in blue) and class variables (in bright blue)"
63
- opt.on :G, :grep, "Filter output by regular expression", :argument => true
61
+ opt.on :G, :grep, "Filter output by regular expression", argument: true
64
62
  if Object.respond_to?(:deprecate_constant)
65
63
  opt.on :d, :dconstants, "Show deprecated constants"
66
64
  end
67
- if jruby?
65
+ if Helpers::Platform.jruby?
68
66
  opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
69
67
  end
70
68
  end
@@ -80,11 +78,11 @@ class Pry
80
78
  @interrogatee = args.empty? ? target_self : target.eval(args.join(' '))
81
79
  raise_errors_if_arguments_are_weird
82
80
  ls_entity = LsEntity.new({
83
- :interrogatee => @interrogatee,
84
- :no_user_opts => no_user_opts?,
85
- :opts => opts,
86
- :args => args,
87
- :_pry_ => _pry_
81
+ interrogatee: @interrogatee,
82
+ no_user_opts: no_user_opts?,
83
+ opts: opts,
84
+ args: args,
85
+ _pry_: _pry_
88
86
  })
89
87
 
90
88
  _pry_.pager.page ls_entity.entities_table
@@ -109,7 +107,6 @@ class Pry
109
107
  raise Pry::CommandError, message if opts.present?(option) && invalid_expr
110
108
  end
111
109
  end
112
-
113
110
  end
114
111
 
115
112
  Pry::Commands.add_command(Pry::Command::Ls)
@@ -31,7 +31,7 @@ class Pry
31
31
  ' "open". `amend-line` can then be used to' \
32
32
  ' modify the method.'
33
33
 
34
- opt.on :e, :expression=, 'Executes until end of valid expression', :as => Integer
34
+ opt.on :e, :expression=, 'Executes until end of valid expression', as: Integer
35
35
  opt.on :p, :print, 'Prints executed code'
36
36
  end
37
37
 
@@ -53,7 +53,6 @@ class Pry
53
53
  end
54
54
  end
55
55
 
56
-
57
56
  def content_after_options
58
57
  if opts.present?(:open)
59
58
  restrict_to_lines(content, (0..-2))
@@ -17,7 +17,7 @@ class Pry
17
17
  BANNER
18
18
 
19
19
  def process
20
- _pry_.pager.page text.bold('Backtrace:') << "\n--\n" << _pry_.backtrace.join("\n")
20
+ _pry_.pager.page bold('Backtrace:') << "\n--\n" << _pry_.backtrace.join("\n")
21
21
  end
22
22
  end
23
23
 
@@ -4,7 +4,7 @@ class Pry
4
4
  match(/raise-up(!?\b.*)/)
5
5
  group 'Context'
6
6
  description 'Raise an exception out of the current pry instance.'
7
- command_options :listing => 'raise-up'
7
+ command_options listing: 'raise-up'
8
8
 
9
9
  banner <<-BANNER
10
10
  Raise up, like exit, allows you to quit pry. Instead of returning a value
@@ -23,6 +23,7 @@ class Pry
23
23
 
24
24
  def process
25
25
  return _pry.pager.page help if captures[0] =~ /(-h|--help)\b/
26
+
26
27
  # Handle 'raise-up', 'raise-up "foo"', 'raise-up RuntimeError, 'farble' in a rubyesque manner
27
28
  target.eval("_pry_.raise_up#{captures[0]}")
28
29
  end
@@ -31,13 +31,14 @@ class Pry
31
31
  @pager = pager
32
32
  super opts
33
33
  end
34
+
34
35
  def page
35
36
  paging_text = StringIO.new
36
37
  yield paging_text
37
38
  @pager.page(paging_text.string)
38
39
  end
39
40
 
40
- def formatter(io)
41
+ def formatter(_io)
41
42
  if @formatter_klass
42
43
  @formatter_klass.new
43
44
  else
@@ -46,14 +47,14 @@ class Pry
46
47
  end
47
48
  end
48
49
 
49
- RDoc::RI.const_set :PryDriver, subclass # hook it up!
50
+ RDoc::RI.const_set :PryDriver, subclass # hook it up!
50
51
  end
51
52
 
52
53
  # Spin-up an RI insance.
53
- ri = RDoc::RI::PryDriver.new _pry_.pager, :use_stdout => true, :interactive => false
54
+ ri = RDoc::RI::PryDriver.new _pry_.pager, use_stdout: true, interactive: false
54
55
 
55
56
  begin
56
- ri.display_names [spec] # Get the documentation (finally!)
57
+ ri.display_names [spec] # Get the documentation (finally!)
57
58
  rescue RDoc::RI::Driver::NotFoundError => e
58
59
  output.puts "error: '#{e.name}' not found"
59
60
  end
@@ -3,8 +3,8 @@ class Pry
3
3
  match(/\.(.*)/)
4
4
  group 'Input and Output'
5
5
  description "All text following a '.' is forwarded to the shell."
6
- command_options :listing => '.<shell command>', :use_prefix => false,
7
- :takes_block => true
6
+ command_options listing: '.<shell command>', use_prefix: false,
7
+ takes_block: true
8
8
 
9
9
  banner <<-'BANNER'
10
10
  Usage: .COMMAND_NAME
@@ -33,6 +33,7 @@ class Pry
33
33
  def parse_destination(dest)
34
34
  return "~" if dest.empty?
35
35
  return dest unless dest == "-"
36
+
36
37
  state.old_pwd || raise(CommandError, "No prior directory available")
37
38
  end
38
39
 
@@ -9,13 +9,13 @@ class Pry
9
9
  BANNER
10
10
 
11
11
  def process
12
- case _pry_.prompt
13
- when Pry::SHELL_PROMPT
14
- _pry_.pop_prompt
15
- _pry_.custom_completions = _pry_.config.file_completions
12
+ state.disabled ^= true
13
+
14
+ if state.disabled
15
+ state.prev_prompt = _pry_.prompt
16
+ _pry_.prompt = Pry::Prompt[:shell][:value]
16
17
  else
17
- _pry_.push_prompt Pry::SHELL_PROMPT
18
- _pry_.custom_completions = _pry_.config.command_completions
18
+ _pry_.prompt = state.prev_prompt
19
19
  end
20
20
  end
21
21
  end
@@ -62,19 +62,17 @@ class Pry
62
62
  # Which sections to include in the 'header', can toggle: :owner,
63
63
  # :signature and visibility.
64
64
  def header_options
65
- super.merge :signature => true
65
+ super.merge signature: true
66
66
  end
67
67
 
68
68
  # figure out start line of docs by back-calculating based on
69
69
  # number of lines in the comment and the start line of the code_object
70
70
  # @return [Fixnum] start line of docs
71
71
  def start_line_for(code_object)
72
- if code_object.command? || opts.present?(:'base-one')
73
- 1
74
- else
75
- code_object.source_line.nil? ? 1 :
76
- (code_object.source_line - code_object.doc.lines.count)
77
- end
72
+ return 1 if code_object.command? || opts.present?(:'base-one')
73
+ return 1 unless code_object.source_line
74
+
75
+ code_object.source_line - code_object.doc.lines.count
78
76
  end
79
77
  end
80
78
 
@@ -2,7 +2,7 @@ class Pry
2
2
  class Command::ShowInfo < Pry::ClassCommand
3
3
  extend Pry::Helpers::BaseHelpers
4
4
 
5
- command_options :shellwords => false, :interpolate => false
5
+ command_options shellwords: false, interpolate: false
6
6
 
7
7
  def initialize(*)
8
8
  super
@@ -11,15 +11,16 @@ class Pry
11
11
  end
12
12
 
13
13
  def options(opt)
14
- opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", :as => :count
14
+ opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", as: :count
15
15
  opt.on :l, "line-numbers", "Show line numbers"
16
16
  opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)"
17
- opt.on :a, :all, "Show all definitions and monkeypatches of the module/class"
17
+ opt.on :a, :all, "Show all definitions and monkeypatches of the module/class"
18
18
  end
19
19
 
20
20
  def process
21
- code_object = Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
21
+ code_object = Pry::CodeObject.lookup(obj_name, _pry_, super: opts[:super])
22
22
  raise CommandError, no_definition_message if !code_object
23
+
23
24
  @original_code_object = code_object
24
25
 
25
26
  if !obj_name && code_object.c_module? && !opts[:all]
@@ -80,7 +81,7 @@ class Pry
80
81
  mod.number_of_candidates.times do |v|
81
82
  candidate = mod.candidate(v)
82
83
  begin
83
- result << "\nCandidate #{v+1}/#{mod.number_of_candidates}: #{candidate.source_file} @ line #{candidate.source_line}:\n"
84
+ result << "\nCandidate #{v + 1}/#{mod.number_of_candidates}: #{candidate.source_file} @ line #{candidate.source_line}:\n"
84
85
  content = content_for(candidate)
85
86
 
86
87
  result << "Number of lines: #{content.lines.count}\n\n" << content
@@ -100,11 +101,17 @@ class Pry
100
101
  # object types: methods, modules, commands, procs...
101
102
  def header(code_object)
102
103
  file_name, line_num = file_and_line_for(code_object)
103
- h = "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} "
104
+ content = content_for(code_object)
105
+
106
+ h = "\n#{bold('From:')} #{file_name} "
104
107
  h << code_object_header(code_object, line_num)
105
- h << "\n#{Pry::Helpers::Text.bold('Number of lines:')} " <<
106
- "#{content_for(code_object).lines.count}\n\n"
107
- 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
108
+ h << "\n#{bold('Number of lines:')} " << "#{content.lines.count}\n\n"
109
+ h << bold('** Warning:') << " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
110
+
111
+ if content.lines.none?
112
+ h << bold('** Warning:') << " Cannot find code for '#{code_object.name}' (source_location is nil)"
113
+ end
114
+
108
115
  h
109
116
  end
110
117
 
@@ -133,11 +140,11 @@ class Pry
133
140
  def module_header(code_object, line_num)
134
141
  h = ""
135
142
  h << "@ line #{line_num}:\n"
136
- h << text.bold(code_object.module? ? "Module" : "Class")
137
- h << " #{text.bold('name:')} #{code_object.nonblank_name}"
143
+ h << bold(code_object.module? ? "Module" : "Class")
144
+ h << " #{bold('name:')} #{code_object.nonblank_name}"
138
145
 
139
146
  if code_object.number_of_candidates > 1
140
- h << (text.bold("\nNumber of monkeypatches: ") << code_object.number_of_candidates.to_s)
147
+ h << (bold("\nNumber of monkeypatches: ") << code_object.number_of_candidates.to_s)
141
148
  h << ". Use the `-a` option to display all available monkeypatches"
142
149
  end
143
150
  h
@@ -145,17 +152,17 @@ class Pry
145
152
 
146
153
  def method_sections(code_object)
147
154
  {
148
- :owner => "\n#{text.bold("Owner:")} #{code_object.owner || "N/A"}\n",
149
- :visibility => "#{text.bold("Visibility:")} #{code_object.visibility}",
150
- :signature => "\n#{text.bold("Signature:")} #{code_object.signature}"
155
+ owner: "\n#{bold("Owner:")} #{code_object.owner || "N/A"}\n",
156
+ visibility: "#{bold("Visibility:")} #{code_object.visibility}",
157
+ signature: "\n#{bold("Signature:")} #{code_object.signature}"
151
158
  }.merge(header_options) { |key, old, new| (new && old).to_s }
152
159
  end
153
160
 
154
161
  def header_options
155
162
  {
156
- :owner => true,
157
- :visibility => true,
158
- :signature => nil
163
+ owner: true,
164
+ visibility: true,
165
+ signature: nil
159
166
  }
160
167
  end
161
168
 
@@ -39,8 +39,11 @@ class Pry
39
39
 
40
40
  # The source for code_object prepared for display.
41
41
  def content_for(code_object)
42
- Code.new(code_object.source, start_line_for(code_object)).
43
- with_line_numbers(use_line_numbers?).highlighted
42
+ code = Code.new(
43
+ code_object.source || [],
44
+ start_line_for(code_object)
45
+ )
46
+ code.with_line_numbers(use_line_numbers?).highlighted
44
47
  end
45
48
  end
46
49
 
@@ -3,7 +3,7 @@ class Pry
3
3
  match 'stat'
4
4
  group 'Introspection'
5
5
  description 'View method information and set _file_ and _dir_ locals.'
6
- command_options :shellwords => false
6
+ command_options shellwords: false
7
7
 
8
8
  banner <<-'BANNER'
9
9
  Usage: stat [OPTIONS] [METH]
@@ -5,7 +5,7 @@ class Pry
5
5
  match 'watch'
6
6
  group 'Context'
7
7
  description 'Watch the value of an expression and print a notification whenever it changes.'
8
- command_options :use_prefix => false
8
+ command_options use_prefix: false
9
9
 
10
10
  banner <<-'BANNER'
11
11
  Usage: watch [EXPRESSION]
@@ -29,7 +29,7 @@ class Pry
29
29
  def options(opt)
30
30
  opt.on :d, :delete,
31
31
  "Delete the watch expression with the given index. If no index is given; clear all watch expressions.",
32
- :optional_argument => true, :as => Integer
32
+ optional_argument: true, as: Integer
33
33
  opt.on :l, :list,
34
34
  "Show all current watch expressions and their values. Calling watch with no expressions or options will also show the watch expressions."
35
35
  end
@@ -54,8 +54,8 @@ class Pry
54
54
 
55
55
  def delete(index)
56
56
  if index
57
- output.puts "Deleting watch expression ##{index}: #{expressions[index-1]}"
58
- expressions.delete_at(index-1)
57
+ output.puts "Deleting watch expression ##{index}: #{expressions[index - 1]}"
58
+ expressions.delete_at(index - 1)
59
59
  else
60
60
  output.puts "Deleting all watched expressions"
61
61
  expressions.clear
@@ -70,7 +70,7 @@ class Pry
70
70
  pager.puts "Listing all watched expressions:"
71
71
  pager.puts ""
72
72
  expressions.each_with_index do |expr, index|
73
- pager.print text.with_line_numbers(expr.to_s, index+1)
73
+ pager.print with_line_numbers(expr.to_s, index + 1)
74
74
  end
75
75
  pager.puts ""
76
76
  end
@@ -81,12 +81,14 @@ class Pry
81
81
  expressions.each do |expr|
82
82
  expr.eval!
83
83
  if expr.changed?
84
- output.puts "#{text.blue "watch"}: #{expr.to_s}"
84
+ output.puts "#{blue "watch"}: #{expr}"
85
85
  end
86
86
  end
87
87
  end
88
88
 
89
- def add_expression(arguments)
89
+ # TODO: fix arguments.
90
+ # https://github.com/pry/pry/commit/b031df2f2f5850ee6e9018f33d35f3485a9b0423
91
+ def add_expression(_arguments)
90
92
  expressions << Expression.new(_pry_, target, arg_string)
91
93
  output.puts "Watching #{Code.new(arg_string).highlighted}"
92
94
  end
@@ -1,6 +1,5 @@
1
1
  class Pry
2
2
  class Command::Whereami < Pry::ClassCommand
3
-
4
3
  def initialize(*)
5
4
  super
6
5
 
@@ -94,7 +93,7 @@ class Pry
94
93
 
95
94
  set_file_and_dir_locals(@file)
96
95
 
97
- out = "\n#{text.bold('From:')} #{location}:\n\n" <<
96
+ out = "\n#{bold('From:')} #{location}:\n\n" <<
98
97
  code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted << "\n"
99
98
 
100
99
  _pry_.pager.page out
@@ -154,8 +153,9 @@ class Pry
154
153
  # or it returns the class of `target_self` if `target_self` is not a class.
155
154
  # @return [Pry::WrappedModule]
156
155
  def target_class
157
- target_self.is_a?(Module) ? Pry::WrappedModule(target_self) :
158
- Pry::WrappedModule(target_self.class)
156
+ return Pry::WrappedModule(target_self) if target_self.is_a?(Module)
157
+
158
+ Pry::WrappedModule(target_self.class)
159
159
  end
160
160
 
161
161
  def class_code
@@ -3,7 +3,7 @@ class Pry
3
3
  match(/wtf([?!]*)/)
4
4
  group 'Context'
5
5
  description 'Show the backtrace of the most recent exception.'
6
- options :listing => 'wtf?'
6
+ options listing: 'wtf?'
7
7
 
8
8
  banner <<-'BANNER'
9
9
  Usage: wtf[?|!]
@@ -26,12 +26,25 @@ class Pry
26
26
  def process
27
27
  raise Pry::CommandError, "No most-recent exception" unless exception
28
28
 
29
- output.puts "#{text.bold('Exception:')} #{exception.class}: #{exception}\n--"
29
+ output.puts "#{bold('Exception:')} #{exception.class}: #{exception}\n--"
30
30
  if opts.verbose?
31
31
  output.puts with_line_numbers(backtrace)
32
32
  else
33
33
  output.puts with_line_numbers(backtrace.first(size_of_backtrace))
34
34
  end
35
+
36
+ if exception.respond_to? :cause
37
+ cause = exception.cause
38
+ while cause
39
+ output.puts "#{text.bold('Caused by:')} #{cause.class}: #{cause}\n--"
40
+ if opts.verbose?
41
+ output.puts with_line_numbers(cause.backtrace)
42
+ else
43
+ output.puts with_line_numbers(cause.backtrace.first(size_of_backtrace))
44
+ end
45
+ cause = cause.cause
46
+ end
47
+ end
35
48
  end
36
49
 
37
50
  private