pry 0.10.4 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +251 -16
  3. data/LICENSE +1 -1
  4. data/README.md +35 -51
  5. data/bin/pry +3 -11
  6. data/lib/pry/basic_object.rb +6 -0
  7. data/lib/pry/cli.rb +50 -52
  8. data/lib/pry/code/code_file.rb +13 -6
  9. data/lib/pry/code/code_range.rb +3 -3
  10. data/lib/pry/code/loc.rb +14 -8
  11. data/lib/pry/code.rb +11 -6
  12. data/lib/pry/code_object.rb +27 -4
  13. data/lib/pry/color_printer.rb +20 -10
  14. data/lib/pry/command.rb +76 -45
  15. data/lib/pry/command_set.rb +17 -45
  16. data/lib/pry/commands/amend_line.rb +3 -4
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat/exception_formatter.rb +10 -8
  19. data/lib/pry/commands/cat/file_formatter.rb +7 -3
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/cat.rb +7 -6
  22. data/lib/pry/commands/change_prompt.rb +29 -9
  23. data/lib/pry/commands/clear_screen.rb +14 -0
  24. data/lib/pry/commands/code_collector.rb +25 -23
  25. data/lib/pry/commands/easter_eggs.rb +12 -12
  26. data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
  27. data/lib/pry/commands/edit.rb +15 -10
  28. data/lib/pry/commands/exit.rb +2 -1
  29. data/lib/pry/commands/find_method.rb +12 -14
  30. data/lib/pry/commands/gem_cd.rb +1 -1
  31. data/lib/pry/commands/gem_install.rb +2 -2
  32. data/lib/pry/commands/gem_list.rb +2 -2
  33. data/lib/pry/commands/gem_open.rb +2 -2
  34. data/lib/pry/commands/gem_readme.rb +25 -0
  35. data/lib/pry/commands/gem_search.rb +40 -0
  36. data/lib/pry/commands/gem_stats.rb +83 -0
  37. data/lib/pry/commands/gist.rb +7 -6
  38. data/lib/pry/commands/help.rb +3 -3
  39. data/lib/pry/commands/hist.rb +11 -10
  40. data/lib/pry/commands/import_set.rb +2 -1
  41. data/lib/pry/commands/install_command.rb +7 -6
  42. data/lib/pry/commands/jump_to.rb +7 -7
  43. data/lib/pry/commands/list_inspectors.rb +2 -2
  44. data/lib/pry/commands/ls/constants.rb +14 -3
  45. data/lib/pry/commands/ls/formatter.rb +4 -2
  46. data/lib/pry/commands/ls/globals.rb +0 -2
  47. data/lib/pry/commands/ls/grep.rb +0 -2
  48. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  49. data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
  50. data/lib/pry/commands/ls/local_names.rb +0 -2
  51. data/lib/pry/commands/ls/local_vars.rb +0 -2
  52. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  53. data/lib/pry/commands/ls/methods.rb +0 -3
  54. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  55. data/lib/pry/commands/ls/self_methods.rb +2 -1
  56. data/lib/pry/commands/ls.rb +30 -31
  57. data/lib/pry/commands/play.rb +3 -4
  58. data/lib/pry/commands/pry_backtrace.rb +1 -1
  59. data/lib/pry/commands/raise_up.rb +2 -1
  60. data/lib/pry/commands/reload_code.rb +2 -2
  61. data/lib/pry/commands/ri.rb +9 -4
  62. data/lib/pry/commands/shell_command.rb +36 -9
  63. data/lib/pry/commands/shell_mode.rb +6 -6
  64. data/lib/pry/commands/show_doc.rb +5 -7
  65. data/lib/pry/commands/show_info.rb +35 -20
  66. data/lib/pry/commands/show_source.rb +5 -2
  67. data/lib/pry/commands/stat.rb +1 -1
  68. data/lib/pry/commands/watch_expression/expression.rb +1 -1
  69. data/lib/pry/commands/watch_expression.rb +9 -7
  70. data/lib/pry/commands/whereami.rb +11 -10
  71. data/lib/pry/commands/wtf.rb +15 -2
  72. data/lib/pry/config/behavior.rb +230 -114
  73. data/lib/pry/config/convenience.rb +24 -21
  74. data/lib/pry/config/default.rb +151 -153
  75. data/lib/pry/config/memoization.rb +48 -0
  76. data/lib/pry/config.rb +30 -19
  77. data/lib/pry/core_extensions.rb +15 -4
  78. data/lib/pry/editor.rb +5 -12
  79. data/lib/pry/exceptions.rb +1 -3
  80. data/lib/pry/forwardable.rb +23 -0
  81. data/lib/pry/helpers/base_helpers.rb +197 -110
  82. data/lib/pry/helpers/command_helpers.rb +5 -4
  83. data/lib/pry/helpers/documentation_helpers.rb +3 -2
  84. data/lib/pry/helpers/options_helpers.rb +6 -6
  85. data/lib/pry/helpers/platform.rb +58 -0
  86. data/lib/pry/helpers/table.rb +20 -15
  87. data/lib/pry/helpers/text.rb +82 -74
  88. data/lib/pry/helpers.rb +1 -0
  89. data/lib/pry/history.rb +43 -9
  90. data/lib/pry/hooks.rb +50 -109
  91. data/lib/pry/indent.rb +21 -19
  92. data/lib/pry/input_completer.rb +146 -123
  93. data/lib/pry/input_lock.rb +0 -2
  94. data/lib/pry/last_exception.rb +2 -2
  95. data/lib/pry/method/disowned.rb +3 -1
  96. data/lib/pry/method/patcher.rb +2 -5
  97. data/lib/pry/method/weird_method_locator.rb +21 -11
  98. data/lib/pry/method.rb +44 -38
  99. data/lib/pry/object_path.rb +5 -4
  100. data/lib/pry/output.rb +37 -37
  101. data/lib/pry/pager.rb +195 -184
  102. data/lib/pry/platform.rb +91 -0
  103. data/lib/pry/plugins.rb +27 -8
  104. data/lib/pry/prompt.rb +144 -25
  105. data/lib/pry/pry_class.rb +83 -33
  106. data/lib/pry/pry_instance.rb +94 -59
  107. data/lib/pry/repl.rb +70 -11
  108. data/lib/pry/repl_file_loader.rb +2 -3
  109. data/lib/pry/ring.rb +84 -0
  110. data/lib/pry/rubygem.rb +9 -7
  111. data/lib/pry/slop/LICENSE +20 -0
  112. data/lib/pry/slop/commands.rb +195 -0
  113. data/lib/pry/slop/option.rb +206 -0
  114. data/lib/pry/slop.rb +661 -0
  115. data/lib/pry/terminal.rb +18 -6
  116. data/lib/pry/testable/evalable.rb +15 -0
  117. data/lib/pry/testable/mockable.rb +14 -0
  118. data/lib/pry/testable/pry_tester.rb +73 -0
  119. data/lib/pry/testable/utility.rb +26 -0
  120. data/lib/pry/testable/variables.rb +46 -0
  121. data/lib/pry/testable.rb +70 -0
  122. data/lib/pry/version.rb +1 -1
  123. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +8 -14
  124. data/lib/pry/wrapped_module.rb +21 -21
  125. data/lib/pry.rb +21 -50
  126. metadata +29 -40
  127. data/lib/pry/commands/list_prompts.rb +0 -35
  128. data/lib/pry/commands/simple_prompt.rb +0 -22
  129. data/lib/pry/history_array.rb +0 -121
  130. data/lib/pry/rbx_path.rb +0 -22
  131. data/lib/pry/test/helper.rb +0 -170
data/lib/pry/cli.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  class Pry
2
-
3
2
  # Manage the processing of command line options
4
3
  class CLI
5
-
6
4
  NoOptionsError = Class.new(StandardError)
7
5
 
8
6
  class << self
9
-
10
7
  # @return [Proc] The Proc defining the valid command line options.
11
8
  attr_accessor :options
12
9
 
@@ -19,7 +16,7 @@ class Pry
19
16
  # as CLI options.
20
17
  attr_accessor :input_args
21
18
 
22
- # Add another set of CLI options (a Slop block)
19
+ # Add another set of CLI options (a Pry::Slop block)
23
20
  def add_options(&block)
24
21
  if options
25
22
  old_options = options
@@ -57,7 +54,7 @@ class Pry
57
54
  self.option_processors = nil
58
55
  end
59
56
 
60
- def parse_options(args=ARGV)
57
+ def parse_options(args = ARGV)
61
58
  unless options
62
59
  raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options."
63
60
  end
@@ -65,39 +62,62 @@ class Pry
65
62
  self.input_args = args
66
63
 
67
64
  begin
68
- opts = Slop.parse!(
65
+ opts = Pry::Slop.parse!(
69
66
  args,
70
- :help => true,
71
- :multiple_switches => false,
72
- :strict => true,
67
+ help: true,
68
+ multiple_switches: false,
69
+ strict: true,
73
70
  &options
74
71
  )
75
- rescue Slop::InvalidOptionError
72
+ rescue Pry::Slop::InvalidOptionError
76
73
  # Display help message on unknown switches and exit.
77
- puts Slop.new(&options)
74
+ puts Pry::Slop.new(&options)
78
75
  exit
79
76
  end
80
77
 
78
+ Pry.initial_session_setup
79
+ Pry.final_session_setup
80
+
81
81
  # Option processors are optional.
82
82
  if option_processors
83
83
  option_processors.each { |processor| processor.call(opts) }
84
84
  end
85
85
 
86
- self
86
+ opts
87
87
  end
88
88
 
89
+ def start(opts)
90
+ exit if opts.help?
91
+
92
+ # invoked via cli
93
+ Pry.cli = true
94
+
95
+ # create the actual context
96
+ if opts[:context]
97
+ Pry.initial_session_setup
98
+ context = Pry.binding_for(eval(opts[:context]))
99
+ Pry.final_session_setup
100
+ else
101
+ context = Pry.toplevel_binding
102
+ end
103
+
104
+ if Pry::CLI.input_args.any? && Pry::CLI.input_args != ["pry"]
105
+ full_name = File.expand_path(Pry::CLI.input_args.first)
106
+ Pry.load_file_through_repl(full_name)
107
+ exit
108
+ end
109
+
110
+ # Start the session (running any code passed with -e, if there is any)
111
+ Pry.start(context, input: StringIO.new(Pry.config.exec_string))
112
+ end
89
113
  end
90
114
 
91
115
  reset
92
116
  end
93
117
  end
94
118
 
95
-
96
- # String that is built to be executed on start (created by -e and -exec switches)
97
- exec_string = ""
98
-
99
119
  # Bring in options defined by plugins
100
- Slop.new do
120
+ Pry::Slop.new do
101
121
  on "no-plugins" do
102
122
  Pry.config.should_load_plugins = false
103
123
  end
@@ -109,14 +129,15 @@ end
109
129
 
110
130
  # The default Pry command line options (before plugin options are included)
111
131
  Pry::CLI.add_options do
112
- banner %{Usage: pry [OPTIONS]
113
- Start a Pry session.
114
- See http://pryrepl.org/ for more information.
115
- Copyright (c) 2013 John Mair (banisterfiend)
116
- --
117
- }
132
+ banner(
133
+ "Usage: pry [OPTIONS]\n" \
134
+ "Start a Pry session.\n" \
135
+ "See http://pryrepl.org/ for more information.\n"
136
+ )
137
+
118
138
  on :e, :exec=, "A line of code to execute in context before the session starts" do |input|
119
- exec_string << input << "\n"
139
+ Pry.config.exec_string += "\n" if Pry.config.exec_string.length > 0
140
+ Pry.config.exec_string += input
120
141
  end
121
142
 
122
143
  on "no-pager", "Disable pager for long output" do
@@ -131,7 +152,7 @@ Copyright (c) 2013 John Mair (banisterfiend)
131
152
  Pry.config.color = false
132
153
  end
133
154
 
134
- on :f, "Suppress loading of ~/.pryrc and ./.pryrc" do
155
+ on :f, "Suppress loading of pryrc" do
135
156
  Pry.config.should_load_rc = false
136
157
  Pry.config.should_load_local_rc = false
137
158
  end
@@ -159,18 +180,18 @@ Copyright (c) 2013 John Mair (banisterfiend)
159
180
  end
160
181
 
161
182
  on "simple-prompt", "Enable simple prompt mode" do
162
- Pry.config.prompt = Pry::SIMPLE_PROMPT
183
+ Pry.config.prompt = Pry::Prompt[:simple][:value]
163
184
  end
164
185
 
165
186
  on "noprompt", "No prompt mode" do
166
- Pry.config.prompt = Pry::NO_PROMPT
187
+ Pry.config.prompt = Pry::Prompt[:none][:value]
167
188
  end
168
189
 
169
190
  on :r, :require=, "`require` a Ruby script at startup" do |file|
170
191
  Pry.config.requires << file
171
192
  end
172
193
 
173
- on :I=, "Add a path to the $LOAD_PATH", :as => Array, :delimiter => ":" do |load_path|
194
+ on :I=, "Add a path to the $LOAD_PATH", as: Array, delimiter: ":" do |load_path|
174
195
  load_path.map! do |path|
175
196
  /\A\.\// =~ path ? path : File.expand_path(path)
176
197
  end
@@ -192,29 +213,6 @@ Copyright (c) 2013 John Mair (banisterfiend)
192
213
 
193
214
  on(:c, :context=,
194
215
  "Start the session in the specified context. Equivalent to `context.pry` in a session.",
195
- :default => "Pry.toplevel_binding"
216
+ default: "Pry.toplevel_binding"
196
217
  )
197
- end.add_option_processor do |opts|
198
-
199
- exit if opts.help?
200
-
201
- # invoked via cli
202
- Pry.cli = true
203
-
204
- # create the actual context
205
- if opts[:context]
206
- Pry.initial_session_setup
207
- context = Pry.binding_for(eval(opts[:context]))
208
- else
209
- context = Pry.toplevel_binding
210
- end
211
-
212
- if Pry::CLI.input_args.any? && Pry::CLI.input_args != ["pry"]
213
- full_name = File.expand_path(Pry::CLI.input_args.first)
214
- Pry.load_file_through_repl(full_name)
215
- exit
216
- end
217
-
218
- # Start the session (running any code passed with -e, if there is any)
219
- Pry.start(context, :input => StringIO.new(exec_string))
220
218
  end
@@ -17,10 +17,18 @@ class Pry
17
17
  %w(.c .h) => :c,
18
18
  %w(.rhtml) => :rhtml,
19
19
  %w(.yaml .yml) => :yaml,
20
- %w(.cpp .hpp .cc .h cxx) => :cpp,
21
- %w(.rb .ru .irbrc .gemspec .pryrc) => :ruby,
20
+ %w(.cpp .hpp .cc .h .cxx) => :cpp,
21
+ %w(.rb .ru .irbrc .gemspec .pryrc .rake) => :ruby,
22
22
  }
23
23
 
24
+ FILES = {
25
+ %w(Gemfile Rakefile Guardfile Capfile) => :ruby
26
+ }
27
+
28
+ # Store the current working directory. This allows show-source etc. to work if
29
+ # your process has changed directory since boot. [Issue #675]
30
+ INITIAL_PWD = Dir.pwd
31
+
24
32
  # @return [Symbol] The type of code stored in this wrapper.
25
33
  attr_reader :code_type
26
34
 
@@ -37,8 +45,6 @@ class Pry
37
45
  Pry.line_buffer.drop(1)
38
46
  elsif Pry::Method::Patcher.code_for(@filename)
39
47
  Pry::Method::Patcher.code_for(@filename)
40
- elsif RbxPath.is_core_path?(@filename)
41
- File.read(RbxPath.convert_path_to_full(@filename))
42
48
  else
43
49
  path = abs_path
44
50
  @code_type = type_from_filename(path)
@@ -79,6 +85,8 @@ class Pry
79
85
  def type_from_filename(filename, default = :unknown)
80
86
  _, @code_type = EXTENSIONS.find do |k, _|
81
87
  k.any? { |ext| ext == File.extname(filename) }
88
+ end || FILES.find do |k, _|
89
+ k.any? { |file_name| file_name == File.basename(filename) }
82
90
  end
83
91
 
84
92
  code_type || default
@@ -91,13 +99,12 @@ class Pry
91
99
 
92
100
  # @return [String]
93
101
  def from_pry_init_pwd
94
- File.expand_path(@filename, Pry::INITIAL_PWD)
102
+ File.expand_path(@filename, INITIAL_PWD)
95
103
  end
96
104
 
97
105
  # @return [String]
98
106
  def from_load_path
99
107
  $LOAD_PATH.map { |path| File.expand_path(@filename, path) }
100
108
  end
101
-
102
109
  end
103
110
  end
@@ -1,11 +1,9 @@
1
1
  class Pry
2
2
  class Code
3
-
4
3
  # Represents a range of lines in a code listing.
5
4
  #
6
5
  # @api private
7
6
  class CodeRange
8
-
9
7
  # @param [Integer] start_line
10
8
  # @param [Integer?] end_line
11
9
  def initialize(start_line, end_line = nil)
@@ -23,6 +21,7 @@ class Pry
23
21
  private
24
22
 
25
23
  def start_line; @start_line; end
24
+
26
25
  def end_line; @end_line; end
27
26
 
28
27
  # If `end_line` is equal to `nil`, then calculate it from the first
@@ -48,12 +47,14 @@ class Pry
48
47
  # @return [Integer]
49
48
  def find_start_index(lines)
50
49
  return start_line if start_line < 0
50
+
51
51
  lines.index { |loc| loc.lineno >= start_line } || lines.length
52
52
  end
53
53
 
54
54
  # @return [Integer]
55
55
  def find_end_index(lines)
56
56
  return end_line if end_line < 0
57
+
57
58
  (lines.index { |loc| loc.lineno > end_line } || 0) - 1
58
59
  end
59
60
 
@@ -66,6 +67,5 @@ class Pry
66
67
  @start_line = start_line.first
67
68
  end
68
69
  end
69
-
70
70
  end
71
71
  end
data/lib/pry/code/loc.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  class Pry
2
2
  class Code
3
-
4
- # Represents a line of code. A line of code is a tuple, which consists of a
5
- # line and a line number. A `LOC` object's state (namely, the line
6
- # parameter) can be changed via instance methods. `Pry::Code` heavily uses
7
- # this class.
3
+ # Represents a line of code (which may, in fact, contain multiple lines if the
4
+ # entirety was eval'd as a single unit following the `edit` command).
5
+ #
6
+ # A line of code is a tuple, which consists of a line and a line number. A
7
+ # `LOC` object's state (namely, the line parameter) can be changed via
8
+ # instance methods. `Pry::Code` heavily uses this class.
8
9
  #
9
10
  # @api private
10
11
  # @example
@@ -18,7 +19,6 @@ class Pry
18
19
  # loc.indent(3)
19
20
  # loc.line #=> " def example\n :example\nend"
20
21
  class LOC
21
-
22
22
  # @return [Array<String, Integer>]
23
23
  attr_reader :tuple
24
24
 
@@ -62,7 +62,8 @@ class Pry
62
62
  def add_line_number(max_width = 0, color = false)
63
63
  padded = lineno.to_s.rjust(max_width)
64
64
  colorized_lineno = color ? Pry::Helpers::BaseHelpers.colorize_code(padded) : padded
65
- tuple[0] = "#{ colorized_lineno }: #{ line }"
65
+ properly_padded_line = handle_multiline_entries_from_edit_command(line, max_width)
66
+ tuple[0] = "#{ colorized_lineno }: #{ properly_padded_line }"
66
67
  end
67
68
 
68
69
  # Prepends a marker "=>" or an empty marker to the +line+.
@@ -86,7 +87,12 @@ class Pry
86
87
  def indent(distance)
87
88
  tuple[0] = "#{ ' ' * distance }#{ line }"
88
89
  end
89
- end
90
90
 
91
+ def handle_multiline_entries_from_edit_command(line, max_width)
92
+ line.split("\n").map.with_index do |inner_line, i|
93
+ i.zero? ? inner_line : "#{' ' * (max_width + 2)}#{inner_line}"
94
+ end.join("\n")
95
+ end
96
+ end
91
97
  end
92
98
  end
data/lib/pry/code.rb CHANGED
@@ -66,7 +66,7 @@ class Pry
66
66
  # @param [Integer, nil] start_line The line number to start on, or nil to
67
67
  # use the method's original line numbers.
68
68
  # @return [Code]
69
- def from_module(mod, candidate_rank = 0, start_line=nil)
69
+ def from_module(mod, candidate_rank = 0, start_line = nil)
70
70
  candidate = Pry::WrappedModule(mod).candidate(candidate_rank)
71
71
  start_line ||= candidate.line
72
72
  new(candidate.source, start_line, :ruby)
@@ -92,7 +92,7 @@ class Pry
92
92
  LOC.new(line, lineno + start_line.to_i) }
93
93
  @code_type = code_type
94
94
 
95
- @with_marker = @with_indentation = nil
95
+ @with_marker = @with_indentation = @with_line_numbers = nil
96
96
  end
97
97
 
98
98
  # Append the given line. +lineno+ is one more than the last existing
@@ -201,6 +201,7 @@ class Pry
201
201
  # @return [Code]
202
202
  def grep(pattern)
203
203
  return self unless pattern
204
+
204
205
  pattern = Regexp.new(pattern)
205
206
 
206
207
  select do |loc|
@@ -265,7 +266,7 @@ class Pry
265
266
 
266
267
  # Writes a formatted representation (based on the configuration of the
267
268
  # object) to the given output, which must respond to `#<<`.
268
- def print_to_output(output, color=false)
269
+ def print_to_output(output, color = false)
269
270
  @lines.each do |loc|
270
271
  loc = loc.dup
271
272
  loc.colorize(@code_type) if color
@@ -291,15 +292,14 @@ class Pry
291
292
  # @param [Integer] line_number (1-based)
292
293
  # @return [String] the code.
293
294
  def expression_at(line_number, consume = 0)
294
- self.class.expression_at(raw, line_number, :consume => consume)
295
+ self.class.expression_at(raw, line_number, consume: consume)
295
296
  end
296
297
 
297
298
  # Get the (approximate) Module.nesting at the give line number.
298
299
  #
299
300
  # @param [Integer] line_number line number starting from 1
300
- # @param [Module] top_module the module in which this code exists
301
301
  # @return [Array<Module>] a list of open modules.
302
- def nesting_at(line_number, top_module = Object)
302
+ def nesting_at(line_number)
303
303
  Pry::Indent.nesting_at(raw, line_number)
304
304
  end
305
305
 
@@ -337,6 +337,11 @@ class Pry
337
337
  end
338
338
  undef =~
339
339
 
340
+ # Check whether String responds to missing methods.
341
+ def respond_to_missing?(name, include_all = false)
342
+ ''.respond_to?(name, include_all)
343
+ end
344
+
340
345
  protected
341
346
 
342
347
  # An abstraction of the `dup.instance_eval` pattern used throughout this
@@ -1,5 +1,4 @@
1
1
  class Pry
2
-
3
2
  # This class is responsible for taking a string (identifying a
4
3
  # command/class/method/etc) and returning the relevant type of object.
5
4
  # For example, if the user looks up "show-source" then a
@@ -37,12 +36,34 @@ class Pry
37
36
  def command?
38
37
  is_a?(Module) && self <= Pry::Command
39
38
  end
39
+
40
+ # @return [Boolean] `true` if this module was defined by means of the C API,
41
+ # `false` if it's a Ruby module.
42
+ # @note If a module defined by C was extended with a lot of methods written
43
+ # in Ruby, this method would fail.
44
+ def c_module?
45
+ if is_a?(WrappedModule)
46
+
47
+ method_locations = wrapped.methods(false).map do |m|
48
+ wrapped.method(m).source_location
49
+ end
50
+
51
+ method_locations.concat(wrapped.instance_methods(false).map do |m|
52
+ wrapped.instance_method(m).source_location
53
+ end)
54
+
55
+ c_methods = method_locations.grep(nil).count
56
+ ruby_methods = method_locations.count - c_methods
57
+
58
+ c_methods > ruby_methods
59
+ end
60
+ end
40
61
  end
41
62
 
42
63
  include Pry::Helpers::CommandHelpers
43
64
 
44
65
  class << self
45
- def lookup(str, _pry_, options={})
66
+ def lookup(str, _pry_, options = {})
46
67
  co = new(str, _pry_, options)
47
68
 
48
69
  co.default_lookup || co.method_or_class_lookup ||
@@ -55,9 +76,9 @@ class Pry
55
76
  attr_accessor :_pry_
56
77
  attr_accessor :super_level
57
78
 
58
- def initialize(str, _pry_, options={})
79
+ def initialize(str, _pry_, options = {})
59
80
  options = {
60
- :super => 0,
81
+ super: 0,
61
82
  }.merge!(options)
62
83
 
63
84
  @str = str
@@ -147,6 +168,8 @@ class Pry
147
168
  # @return [Boolean]
148
169
  def safe_to_evaluate?(str)
149
170
  return true if str.strip == "self"
171
+ return false if str =~ /%/
172
+
150
173
  kind = target.eval("defined?(#{str})")
151
174
  kind =~ /variable|constant/
152
175
  end
@@ -12,8 +12,8 @@ class Pry
12
12
 
13
13
  CodeRay::Encoders::Terminal::TOKEN_COLORS[:comment][:self] = "\e[1;34m"
14
14
 
15
- def self.pp(obj, out = $>, width = 79)
16
- q = ColorPrinter.new(out, width)
15
+ def self.pp(obj, out = $>, width = 79, newline = "\n")
16
+ q = ColorPrinter.new(out, width, newline)
17
17
  q.guard_inspect_key { q.pp obj }
18
18
  q.flush
19
19
  out << "\n"
@@ -31,17 +31,27 @@ class Pry
31
31
  end
32
32
 
33
33
  def pp(obj)
34
- super
34
+ if String === obj
35
+ # Avoid calling Ruby 2.4+ String#pretty_print that prints multiline
36
+ # Strings prettier
37
+ text(obj.inspect)
38
+ else
39
+ super
40
+ end
35
41
  rescue => e
36
42
  raise if e.is_a? Pry::Pager::StopPaging
37
43
 
38
- # Read the class name off of the singleton class to provide a default
39
- # inspect.
40
- singleton = class << obj; self; end
41
- ancestors = Pry::Method.safe_send(singleton, :ancestors)
42
- klass = ancestors.reject { |k| k == singleton }.first
43
- obj_id = obj.__id__.to_s(16) rescue 0
44
- str = "#<#{klass}:0x#{obj_id}>"
44
+ begin
45
+ str = obj.inspect
46
+ rescue Exception
47
+ # Read the class name off of the singleton class to provide a default
48
+ # inspect.
49
+ singleton = class << obj; self; end
50
+ ancestors = Pry::Method.safe_send(singleton, :ancestors)
51
+ klass = ancestors.reject { |k| k == singleton }.first
52
+ obj_id = obj.__id__.to_s(16) rescue 0
53
+ str = "#<#{klass}:0x#{obj_id}>"
54
+ end
45
55
 
46
56
  text highlight_object_literal(str)
47
57
  end