pry 0.10.3 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +439 -16
- data/LICENSE +1 -1
- data/README.md +362 -302
- data/bin/pry +4 -7
- data/lib/pry/basic_object.rb +10 -0
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +84 -97
- data/lib/pry/code/code_file.rb +37 -26
- data/lib/pry/code/code_range.rb +7 -5
- data/lib/pry/code/loc.rb +26 -13
- data/lib/pry/code.rb +42 -31
- data/lib/pry/code_object.rb +53 -28
- data/lib/pry/color_printer.rb +46 -35
- data/lib/pry/command.rb +197 -369
- data/lib/pry/command_set.rb +89 -114
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -82
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +85 -72
- data/lib/pry/commands/cat/file_formatter.rb +56 -46
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +62 -54
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +48 -23
- data/lib/pry/commands/clear_screen.rb +20 -0
- data/lib/pry/commands/code_collector.rb +148 -131
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +23 -34
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/edit.rb +185 -157
- data/lib/pry/commands/exit.rb +40 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -162
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -149
- data/lib/pry/commands/import_set.rb +20 -15
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls/constants.rb +59 -31
- data/lib/pry/commands/ls/formatter.rb +42 -36
- data/lib/pry/commands/ls/globals.rb +38 -36
- data/lib/pry/commands/ls/grep.rb +17 -15
- data/lib/pry/commands/ls/instance_vars.rb +29 -28
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -24
- data/lib/pry/commands/ls/local_vars.rb +38 -30
- data/lib/pry/commands/ls/ls_entity.rb +47 -52
- data/lib/pry/commands/ls/methods.rb +49 -51
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -21
- data/lib/pry/commands/ls.rb +124 -103
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +92 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +33 -27
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +57 -42
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +56 -29
- data/lib/pry/commands/shell_mode.rb +22 -18
- data/lib/pry/commands/show_doc.rb +80 -70
- data/lib/pry/commands/show_info.rb +194 -155
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -42
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/watch_expression.rb +89 -84
- data/lib/pry/commands/whereami.rb +156 -141
- data/lib/pry/commands/wtf.rb +78 -40
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/config.rb +310 -20
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +22 -9
- data/lib/pry/editor.rb +56 -34
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -18
- data/lib/pry/forwardable.rb +27 -0
- data/lib/pry/helpers/base_helpers.rb +20 -62
- data/lib/pry/helpers/command_helpers.rb +52 -62
- data/lib/pry/helpers/documentation_helpers.rb +21 -12
- data/lib/pry/helpers/options_helpers.rb +15 -8
- data/lib/pry/helpers/platform.rb +55 -0
- data/lib/pry/helpers/table.rb +44 -32
- data/lib/pry/helpers/text.rb +96 -85
- data/lib/pry/helpers.rb +3 -0
- data/lib/pry/history.rb +81 -55
- data/lib/pry/hooks.rb +60 -110
- data/lib/pry/indent.rb +74 -68
- data/lib/pry/input_completer.rb +199 -158
- data/lib/pry/input_lock.rb +7 -10
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method/disowned.rb +19 -5
- data/lib/pry/method/patcher.rb +14 -8
- data/lib/pry/method/weird_method_locator.rb +79 -45
- data/lib/pry/method.rb +178 -124
- data/lib/pry/object_path.rb +37 -28
- data/lib/pry/output.rb +102 -16
- data/lib/pry/pager.rb +187 -174
- data/lib/pry/prompt.rb +213 -25
- data/lib/pry/pry_class.rb +119 -98
- data/lib/pry/pry_instance.rb +261 -224
- data/lib/pry/repl.rb +83 -29
- data/lib/pry/repl_file_loader.rb +27 -22
- data/lib/pry/ring.rb +89 -0
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +190 -0
- data/lib/pry/slop/option.rb +210 -0
- data/lib/pry/slop.rb +672 -0
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +24 -0
- data/lib/pry/testable/mockable.rb +22 -0
- data/lib/pry/testable/pry_tester.rb +88 -0
- data/lib/pry/testable/utility.rb +34 -0
- data/lib/pry/testable/variables.rb +52 -0
- data/lib/pry/testable.rb +68 -0
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +20 -0
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +35 -32
- data/lib/pry/wrapped_module.rb +68 -63
- data/lib/pry.rb +133 -149
- metadata +58 -69
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gist.rb +0 -101
- data/lib/pry/commands/install_command.rb +0 -53
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/config/behavior.rb +0 -139
- data/lib/pry/config/convenience.rb +0 -25
- data/lib/pry/config/default.rb +0 -161
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/plugins.rb +0 -103
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/rubygem.rb +0 -82
- data/lib/pry/terminal.rb +0 -79
- data/lib/pry/test/helper.rb +0 -170
data/lib/pry/last_exception.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
4
|
# {Pry::LastException} is a proxy class who wraps an Exception object for
|
3
5
|
# {Pry#last_exception}. it extends the exception object with methods that
|
@@ -6,56 +8,54 @@
|
|
6
8
|
# the original exception object is not modified and method calls are forwarded
|
7
9
|
# to the wrapped exception object.
|
8
10
|
#
|
9
|
-
class Pry
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def method_missing(name, *args, &block)
|
19
|
-
if @e.respond_to?(name)
|
20
|
-
@e.public_send(name, *args, &block)
|
21
|
-
else
|
22
|
-
super
|
11
|
+
class Pry
|
12
|
+
class LastException < BasicObject
|
13
|
+
attr_accessor :bt_index
|
14
|
+
|
15
|
+
def initialize(exception)
|
16
|
+
@exception = exception
|
17
|
+
@bt_index = 0
|
18
|
+
@file, @line = bt_source_location_for(0)
|
23
19
|
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def respond_to_missing?(name, include_private = false)
|
27
|
-
@e.respond_to?(name)
|
28
|
-
end
|
29
20
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
21
|
+
def method_missing(name, *args, &block)
|
22
|
+
if @exception.respond_to?(name)
|
23
|
+
@exception.public_send(name, *args, &block)
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
37
28
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
def line
|
43
|
-
@line
|
44
|
-
end
|
29
|
+
def respond_to_missing?(name, include_all = false)
|
30
|
+
@exception.respond_to?(name, include_all)
|
31
|
+
end
|
45
32
|
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
# returns the path to a file for the current backtrace. see {#bt_index}.
|
36
|
+
#
|
37
|
+
attr_reader :file
|
38
|
+
|
39
|
+
#
|
40
|
+
# @return [Fixnum]
|
41
|
+
# returns the line for the current backtrace. see {#bt_index}.
|
42
|
+
#
|
43
|
+
attr_reader :line
|
44
|
+
|
45
|
+
# @return [Exception]
|
46
|
+
# returns the wrapped exception
|
47
|
+
#
|
48
|
+
def wrapped_exception
|
49
|
+
@exception
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def bt_source_location_for(index)
|
53
|
+
backtrace[index] =~ /(.*):(\d+)/
|
54
|
+
[::Regexp.last_match(1), ::Regexp.last_match(2).to_i]
|
55
|
+
end
|
57
56
|
|
58
|
-
|
59
|
-
|
57
|
+
def inc_bt_index
|
58
|
+
@bt_index = (@bt_index + 1) % backtrace.size
|
59
|
+
end
|
60
60
|
end
|
61
61
|
end
|
data/lib/pry/method/disowned.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
class Method
|
3
5
|
# A Disowned Method is one that's been removed from the class on which it was defined.
|
@@ -20,8 +22,10 @@ class Pry
|
|
20
22
|
#
|
21
23
|
# @param [Object] receiver
|
22
24
|
# @param [String] method_name
|
23
|
-
def initialize(receiver, method_name
|
24
|
-
@receiver
|
25
|
+
def initialize(receiver, method_name)
|
26
|
+
@receiver = receiver
|
27
|
+
@name = method_name
|
28
|
+
@method = nil
|
25
29
|
end
|
26
30
|
|
27
31
|
# Is the method undefined? (aka `Disowned`)
|
@@ -44,9 +48,19 @@ class Pry
|
|
44
48
|
end
|
45
49
|
|
46
50
|
# Raise a more useful error message instead of trying to forward to nil.
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
# rubocop:disable Style/MethodMissingSuper
|
52
|
+
def method_missing(method_name, *args, &block)
|
53
|
+
if method(:name).respond_to?(method_name)
|
54
|
+
raise "Cannot call '#{method_name}' on an undef'd method."
|
55
|
+
end
|
56
|
+
|
57
|
+
method = Object.instance_method(:method_missing).bind(self)
|
58
|
+
method.call(method_name, *args, &block)
|
59
|
+
end
|
60
|
+
# rubocop:enable Style/MethodMissingSuper
|
61
|
+
|
62
|
+
def respond_to_missing?(method_name, include_private = false)
|
63
|
+
!method(:name).respond_to?(method_name) || super
|
50
64
|
end
|
51
65
|
end
|
52
66
|
end
|
data/lib/pry/method/patcher.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
class Method
|
3
5
|
class Patcher
|
4
6
|
attr_accessor :method
|
5
7
|
|
8
|
+
# rubocop:disable Style/ClassVars
|
6
9
|
@@source_cache = {}
|
10
|
+
# rubocop:enable Style/ClassVars
|
7
11
|
|
8
12
|
def initialize(method)
|
9
13
|
@method = method
|
@@ -42,9 +46,6 @@ class Pry
|
|
42
46
|
# transation we make that not happen, which means that alias_method_chains, etc.
|
43
47
|
# continue to work.
|
44
48
|
#
|
45
|
-
# @param [String] meth_name The method name before aliasing
|
46
|
-
# @param [Module] target The owner of the method
|
47
|
-
|
48
49
|
def with_method_transaction
|
49
50
|
temp_name = "__pry_#{method.original_name}__"
|
50
51
|
method = self.method
|
@@ -54,9 +55,12 @@ class Pry
|
|
54
55
|
alias_method method.name, method.original_name
|
55
56
|
alias_method method.original_name, temp_name
|
56
57
|
end
|
57
|
-
|
58
58
|
ensure
|
59
|
-
|
59
|
+
begin
|
60
|
+
method.send(:remove_method, temp_name)
|
61
|
+
rescue StandardError
|
62
|
+
nil
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
66
|
# Update the definition line so that it can be eval'd directly on the Method's
|
@@ -75,7 +79,9 @@ class Pry
|
|
75
79
|
if line =~ /\Adef (?:.*?\.)?#{Regexp.escape(method.original_name)}(?=[\(\s;]|$)/
|
76
80
|
"def #{method.original_name}#{$'}"
|
77
81
|
else
|
78
|
-
raise CommandError,
|
82
|
+
raise CommandError,
|
83
|
+
"Could not find original `def #{method.original_name}` line " \
|
84
|
+
"to patch."
|
79
85
|
end
|
80
86
|
end
|
81
87
|
|
@@ -97,7 +103,7 @@ class Pry
|
|
97
103
|
def wrap_for_owner(source)
|
98
104
|
Pry.current[:pry_owner] = method.owner
|
99
105
|
owner_source = definition_for_owner(source)
|
100
|
-
visibility_fix = "#{method.visibility
|
106
|
+
visibility_fix = "#{method.visibility} #{method.name.to_sym.inspect}"
|
101
107
|
"Pry.current[:pry_owner].class_eval do; #{owner_source}\n#{visibility_fix}\nend"
|
102
108
|
end
|
103
109
|
|
@@ -116,7 +122,7 @@ class Pry
|
|
116
122
|
def wrap_for_nesting(source)
|
117
123
|
nesting = Pry::Code.from_file(method.source_file).nesting_at(method.source_line)
|
118
124
|
|
119
|
-
(nesting + [source] + nesting.map{ "end" } + [""]).join(";")
|
125
|
+
(nesting + [source] + nesting.map { "end" } + [""]).join(";")
|
120
126
|
rescue Pry::Indent::UnparseableNestingError
|
121
127
|
source
|
122
128
|
end
|
@@ -1,38 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
class Method
|
3
|
-
|
4
5
|
# This class is responsible for locating the *real* `Pry::Method`
|
5
6
|
# object captured by a binding.
|
6
7
|
#
|
7
8
|
# Given a `Binding` from inside a method and a 'seed' Pry::Method object,
|
8
9
|
# there are primarily two situations where the seed method doesn't match
|
9
10
|
# the Binding:
|
10
|
-
# 1. The Pry::Method is from a subclass
|
11
|
-
#
|
12
|
-
# search vertically up the
|
13
|
-
# and for 2. we search laterally along the object's
|
11
|
+
# 1. The Pry::Method is from a subclass
|
12
|
+
# 2. The Pry::Method represents a method of the same name while the original
|
13
|
+
# was renamed to something else. For 1. we search vertically up the
|
14
|
+
# inheritance chain, and for 2. we search laterally along the object's
|
15
|
+
# method table.
|
14
16
|
#
|
15
17
|
# When we locate the method that matches the Binding we wrap it in
|
16
18
|
# Pry::Method and return it, or return nil if we fail.
|
17
19
|
class WeirdMethodLocator
|
18
20
|
class << self
|
19
|
-
|
20
21
|
# Whether the given method object matches the associated binding.
|
21
22
|
# If the method object does not match the binding, then it's
|
22
23
|
# most likely not the method captured by the binding, and we
|
23
24
|
# must commence a search.
|
24
25
|
#
|
25
26
|
# @param [Pry::Method] method
|
26
|
-
# @param [Binding]
|
27
|
+
# @param [Binding] binding
|
27
28
|
# @return [Boolean]
|
28
|
-
def normal_method?(method,
|
29
|
-
method &&
|
30
|
-
|
31
|
-
|
29
|
+
def normal_method?(method, binding)
|
30
|
+
if method && method.source_file && method.source_range
|
31
|
+
if binding.respond_to?(:source_location)
|
32
|
+
binding_file, binding_line = binding.source_location
|
33
|
+
else
|
34
|
+
binding_file = binding.eval('__FILE__')
|
35
|
+
binding_line = binding.eval('__LINE__')
|
36
|
+
end
|
37
|
+
(File.expand_path(method.source_file) == File.expand_path(binding_file)) &&
|
38
|
+
method.source_range.include?(binding_line)
|
39
|
+
end
|
40
|
+
rescue StandardError
|
41
|
+
false
|
32
42
|
end
|
33
43
|
|
34
|
-
def weird_method?(method,
|
35
|
-
!normal_method?(method,
|
44
|
+
def weird_method?(method, binding)
|
45
|
+
!normal_method?(method, binding)
|
36
46
|
end
|
37
47
|
end
|
38
48
|
|
@@ -43,12 +53,13 @@ class Pry
|
|
43
53
|
# @param [Binding] target The Binding that captures the method
|
44
54
|
# we want to locate.
|
45
55
|
def initialize(method, target)
|
46
|
-
@method
|
56
|
+
@method = method
|
57
|
+
@target = target
|
47
58
|
end
|
48
59
|
|
49
60
|
# @return [Pry::Method, nil] The Pry::Method that matches the
|
50
61
|
# given binding.
|
51
|
-
def
|
62
|
+
def find_method
|
52
63
|
find_method_in_superclass || find_renamed_method
|
53
64
|
end
|
54
65
|
|
@@ -56,11 +67,16 @@ class Pry
|
|
56
67
|
# This usually happens when the method captured by the Binding
|
57
68
|
# has been subsequently deleted.
|
58
69
|
def lost_method?
|
59
|
-
!!(
|
70
|
+
!!(find_method.nil? && renamed_method_source_location)
|
60
71
|
end
|
61
72
|
|
62
73
|
private
|
63
74
|
|
75
|
+
def skip_superclass_search?
|
76
|
+
target_mod = @target.eval('self').class
|
77
|
+
target_mod.ancestors.take_while { |mod| mod != target_mod }.any?
|
78
|
+
end
|
79
|
+
|
64
80
|
def normal_method?(method)
|
65
81
|
self.class.normal_method?(method, target)
|
66
82
|
end
|
@@ -70,50 +86,64 @@ class Pry
|
|
70
86
|
end
|
71
87
|
|
72
88
|
def target_file
|
73
|
-
|
89
|
+
file =
|
90
|
+
if target.respond_to?(:source_location)
|
91
|
+
target.source_location.first
|
92
|
+
else
|
93
|
+
target.eval('__FILE__')
|
94
|
+
end
|
95
|
+
pry_file? ? file : File.expand_path(file)
|
74
96
|
end
|
75
97
|
|
76
98
|
def target_line
|
77
|
-
target.
|
99
|
+
if target.respond_to?(:source_location)
|
100
|
+
target.source_location.last
|
101
|
+
else
|
102
|
+
target.eval('__LINE__')
|
103
|
+
end
|
78
104
|
end
|
79
105
|
|
80
106
|
def pry_file?
|
81
|
-
|
107
|
+
file =
|
108
|
+
if target.respond_to?(:source_location)
|
109
|
+
target.source_location.first
|
110
|
+
else
|
111
|
+
target.eval('__FILE__')
|
112
|
+
end
|
113
|
+
Pry.eval_path == file
|
82
114
|
end
|
83
115
|
|
84
|
-
# it's possible in some cases that the method we find by this approach is
|
85
|
-
# the one we're currently in, consider:
|
116
|
+
# it's possible in some cases that the method we find by this approach is
|
117
|
+
# a sub-method of the one we're currently in, consider:
|
86
118
|
#
|
87
119
|
# class A; def b; binding.pry; end; end
|
88
120
|
# class B < A; def b; super; end; end
|
89
121
|
#
|
90
|
-
# Given that we can normally find the source_range of methods, and that we
|
91
|
-
# __FILE__ and __LINE__ the binding is at, we can hope to
|
122
|
+
# Given that we can normally find the source_range of methods, and that we
|
123
|
+
# know which __FILE__ and __LINE__ the binding is at, we can hope to
|
124
|
+
# disambiguate these cases.
|
92
125
|
#
|
93
|
-
# This obviously won't work if the source is unavaiable for some reason,
|
94
|
-
# methods have the same __FILE__ and __LINE__
|
95
|
-
# is broken.
|
126
|
+
# This obviously won't work if the source is unavaiable for some reason,
|
127
|
+
# or if both methods have the same __FILE__ and __LINE__.
|
96
128
|
#
|
97
129
|
# @return [Pry::Method, nil] The Pry::Method representing the
|
98
130
|
# superclass method.
|
99
131
|
def find_method_in_superclass
|
100
132
|
guess = method
|
133
|
+
return guess if skip_superclass_search?
|
101
134
|
|
102
135
|
while guess
|
103
136
|
# needs rescue if this is a Disowned method or a C method or something...
|
104
137
|
# TODO: Fix up the exception handling so we don't need a bare rescue
|
105
|
-
if normal_method?(guess)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
else
|
110
|
-
break
|
111
|
-
end
|
138
|
+
return guess if normal_method?(guess)
|
139
|
+
break if guess == guess.super
|
140
|
+
|
141
|
+
guess = guess.super
|
112
142
|
end
|
113
143
|
|
114
|
-
# Uhoh... none of the methods in the chain had the right __FILE__ and
|
115
|
-
#
|
116
|
-
#
|
144
|
+
# Uhoh... none of the methods in the chain had the right `__FILE__` and
|
145
|
+
# `__LINE__` due to unknown circumstances.
|
146
|
+
# TODO: we should warn the user when this happens.
|
117
147
|
nil
|
118
148
|
end
|
119
149
|
|
@@ -124,21 +154,23 @@ class Pry
|
|
124
154
|
# @return [Pry::Method, nil] The Pry::Method representing the
|
125
155
|
# renamed method
|
126
156
|
def find_renamed_method
|
127
|
-
return
|
157
|
+
return unless valid_file?(target_file)
|
158
|
+
|
128
159
|
alias_name = all_methods_for(target_self).find do |v|
|
129
|
-
|
160
|
+
location = target_self.method(v).source_location
|
161
|
+
location && expanded_source_location(location) == renamed_method_source_location
|
130
162
|
end
|
131
163
|
|
132
164
|
alias_name && Pry::Method(target_self.method(alias_name))
|
133
165
|
end
|
134
166
|
|
135
|
-
def expanded_source_location(
|
136
|
-
return
|
167
|
+
def expanded_source_location(source_location)
|
168
|
+
return unless source_location
|
137
169
|
|
138
170
|
if pry_file?
|
139
|
-
|
171
|
+
source_location
|
140
172
|
else
|
141
|
-
[File.expand_path(
|
173
|
+
[File.expand_path(source_location.first), source_location.last]
|
142
174
|
end
|
143
175
|
end
|
144
176
|
|
@@ -150,14 +182,16 @@ class Pry
|
|
150
182
|
# @return [Array<String, Fixnum>] The `source_location` of the
|
151
183
|
# renamed method
|
152
184
|
def renamed_method_source_location
|
153
|
-
|
185
|
+
if defined?(@original_method_source_location)
|
186
|
+
return @original_method_source_location
|
187
|
+
end
|
154
188
|
|
155
189
|
source_index = lines_for_file(target_file)[0..(target_line - 1)].rindex do |v|
|
156
190
|
Pry::Method.method_definition?(method.name, v)
|
157
191
|
end
|
158
192
|
|
159
|
-
@original_method_source_location =
|
160
|
-
[target_file, index_to_line_number(source_index)]
|
193
|
+
@original_method_source_location =
|
194
|
+
source_index && [target_file, index_to_line_number(source_index)]
|
161
195
|
end
|
162
196
|
|
163
197
|
def index_to_line_number(index)
|