pry 0.11.3 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +139 -1
- data/LICENSE +1 -1
- data/README.md +13 -30
- data/bin/pry +0 -4
- data/lib/pry.rb +17 -47
- data/lib/pry/cli.rb +17 -24
- data/lib/pry/code.rb +6 -6
- data/lib/pry/code/code_file.rb +5 -4
- data/lib/pry/code/code_range.rb +3 -3
- data/lib/pry/code/loc.rb +14 -8
- data/lib/pry/code_object.rb +4 -4
- data/lib/pry/color_printer.rb +1 -0
- data/lib/pry/command.rb +36 -29
- data/lib/pry/command_set.rb +17 -52
- data/lib/pry/commands/amend_line.rb +3 -4
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +7 -6
- data/lib/pry/commands/cat/exception_formatter.rb +9 -8
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/change_prompt.rb +29 -9
- data/lib/pry/commands/clear_screen.rb +14 -0
- data/lib/pry/commands/code_collector.rb +9 -9
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +8 -7
- data/lib/pry/commands/exit.rb +2 -1
- data/lib/pry/commands/find_method.rb +11 -13
- data/lib/pry/commands/gem_cd.rb +1 -1
- data/lib/pry/commands/gem_install.rb +2 -2
- data/lib/pry/commands/gem_list.rb +2 -2
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gem_search.rb +2 -2
- data/lib/pry/commands/gem_stats.rb +83 -0
- data/lib/pry/commands/gist.rb +7 -6
- data/lib/pry/commands/help.rb +3 -3
- data/lib/pry/commands/hist.rb +9 -8
- data/lib/pry/commands/import_set.rb +2 -1
- data/lib/pry/commands/install_command.rb +7 -6
- data/lib/pry/commands/list_inspectors.rb +2 -2
- data/lib/pry/commands/ls.rb +27 -30
- data/lib/pry/commands/ls/constants.rb +4 -4
- data/lib/pry/commands/ls/formatter.rb +3 -2
- data/lib/pry/commands/ls/globals.rb +0 -2
- data/lib/pry/commands/ls/grep.rb +0 -2
- data/lib/pry/commands/ls/instance_vars.rb +0 -1
- data/lib/pry/commands/ls/local_names.rb +0 -2
- data/lib/pry/commands/ls/local_vars.rb +0 -2
- data/lib/pry/commands/ls/ls_entity.rb +0 -1
- data/lib/pry/commands/ls/methods.rb +0 -3
- data/lib/pry/commands/ls/methods_helper.rb +1 -1
- data/lib/pry/commands/ls/self_methods.rb +0 -1
- data/lib/pry/commands/play.rb +1 -2
- data/lib/pry/commands/pry_backtrace.rb +1 -1
- data/lib/pry/commands/raise_up.rb +2 -1
- data/lib/pry/commands/ri.rb +5 -4
- data/lib/pry/commands/shell_command.rb +3 -2
- data/lib/pry/commands/shell_mode.rb +6 -6
- data/lib/pry/commands/show_doc.rb +5 -7
- data/lib/pry/commands/show_info.rb +25 -18
- data/lib/pry/commands/show_source.rb +5 -2
- data/lib/pry/commands/stat.rb +1 -1
- data/lib/pry/commands/watch_expression.rb +9 -7
- data/lib/pry/commands/whereami.rb +4 -4
- data/lib/pry/commands/wtf.rb +15 -2
- data/lib/pry/config.rb +33 -9
- data/lib/pry/config/behavior.rb +229 -205
- data/lib/pry/config/convenience.rb +24 -21
- data/lib/pry/config/default.rb +153 -143
- data/lib/pry/config/memoization.rb +41 -37
- data/lib/pry/core_extensions.rb +4 -3
- data/lib/pry/editor.rb +5 -12
- data/lib/pry/exceptions.rb +0 -2
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +133 -4
- data/lib/pry/helpers/command_helpers.rb +5 -4
- data/lib/pry/helpers/documentation_helpers.rb +2 -2
- data/lib/pry/helpers/options_helpers.rb +5 -5
- data/lib/pry/helpers/platform.rb +58 -0
- data/lib/pry/helpers/table.rb +20 -15
- data/lib/pry/helpers/text.rb +3 -4
- data/lib/pry/history.rb +21 -8
- data/lib/pry/hooks.rb +3 -3
- data/lib/pry/indent.rb +15 -17
- data/lib/pry/input_completer.rb +12 -7
- data/lib/pry/input_lock.rb +0 -2
- data/lib/pry/last_exception.rb +1 -1
- data/lib/pry/method.rb +37 -31
- data/lib/pry/method/disowned.rb +2 -1
- data/lib/pry/method/patcher.rb +2 -2
- data/lib/pry/method/weird_method_locator.rb +7 -8
- data/lib/pry/object_path.rb +5 -4
- data/lib/pry/output.rb +3 -2
- data/lib/pry/pager.rb +4 -3
- data/lib/pry/platform.rb +79 -81
- data/lib/pry/plugins.rb +7 -3
- data/lib/pry/prompt.rb +144 -25
- data/lib/pry/pry_class.rb +53 -29
- data/lib/pry/pry_instance.rb +88 -55
- data/lib/pry/repl.rb +33 -4
- data/lib/pry/repl_file_loader.rb +1 -2
- data/lib/pry/ring.rb +84 -0
- data/lib/pry/rubygem.rb +6 -6
- data/lib/pry/slop.rb +17 -17
- data/lib/pry/slop/commands.rb +3 -4
- data/lib/pry/slop/option.rb +19 -21
- data/lib/pry/terminal.rb +2 -1
- data/lib/pry/testable/mockable.rb +2 -2
- data/lib/pry/testable/pry_tester.rb +1 -1
- data/lib/pry/testable/utility.rb +2 -2
- data/lib/pry/testable/variables.rb +1 -1
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +15 -15
- data/lib/pry/wrapped_module/candidate.rb +2 -2
- metadata +17 -29
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/rbx_path.rb +0 -22
data/lib/pry/helpers/text.rb
CHANGED
@@ -18,11 +18,11 @@ class Pry
|
|
18
18
|
|
19
19
|
COLORS.each_pair do |color, value|
|
20
20
|
define_method color do |text|
|
21
|
-
"\033[0;#{30+value}m#{text}\033[0m"
|
21
|
+
"\033[0;#{30 + value}m#{text}\033[0m"
|
22
22
|
end
|
23
23
|
|
24
24
|
define_method "bright_#{color}" do |text|
|
25
|
-
"\033[1;#{30+value}m#{text}\033[0m"
|
25
|
+
"\033[1;#{30 + value}m#{text}\033[0m"
|
26
26
|
end
|
27
27
|
|
28
28
|
COLORS.each_pair do |bg_color, bg_value|
|
@@ -60,7 +60,6 @@ class Pry
|
|
60
60
|
def default(text)
|
61
61
|
text.to_s
|
62
62
|
end
|
63
|
-
alias_method :bright_default, :bold
|
64
63
|
|
65
64
|
#
|
66
65
|
# @yield
|
@@ -95,7 +94,7 @@ class Pry
|
|
95
94
|
# @param [#each_line] text
|
96
95
|
# @param [Fixnum] offset
|
97
96
|
# @return [String]
|
98
|
-
def with_line_numbers(text, offset, color
|
97
|
+
def with_line_numbers(text, offset, color = :blue)
|
99
98
|
lines = text.each_line.to_a
|
100
99
|
max_width = (offset + lines.count).to_s.length
|
101
100
|
lines.each_with_index.map do |line, index|
|
data/lib/pry/history.rb
CHANGED
@@ -7,7 +7,7 @@ class Pry
|
|
7
7
|
# @return [Fixnum] Number of lines in history when Pry first loaded.
|
8
8
|
attr_reader :original_lines
|
9
9
|
|
10
|
-
def initialize(options={})
|
10
|
+
def initialize(options = {})
|
11
11
|
@history = []
|
12
12
|
@original_lines = 0
|
13
13
|
@file_path = options[:file_path]
|
@@ -25,8 +25,8 @@ class Pry
|
|
25
25
|
@pusher = method(:push_to_readline)
|
26
26
|
@clearer = method(:clear_readline)
|
27
27
|
else
|
28
|
-
@pusher = proc {
|
29
|
-
@clearer = proc {
|
28
|
+
@pusher = proc {}
|
29
|
+
@clearer = proc {}
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,6 +34,8 @@ class Pry
|
|
34
34
|
# @return [Integer] The number of lines loaded
|
35
35
|
def load
|
36
36
|
@loader.call do |line|
|
37
|
+
next if invalid_readline_line?(line)
|
38
|
+
|
37
39
|
@pusher.call(line.chomp)
|
38
40
|
@history << line.chomp
|
39
41
|
@original_lines += 1
|
@@ -44,7 +46,9 @@ class Pry
|
|
44
46
|
# @param [String] line
|
45
47
|
# @return [String] The same line that was passed in
|
46
48
|
def push(line)
|
47
|
-
|
49
|
+
empty_or_invalid_line = line.empty? || invalid_readline_line?(line)
|
50
|
+
|
51
|
+
unless empty_or_invalid_line || (@history.last && line == @history.last)
|
48
52
|
@pusher.call(line)
|
49
53
|
@history << line
|
50
54
|
if !should_ignore?(line) && Pry.config.history.should_save
|
@@ -107,8 +111,8 @@ class Pry
|
|
107
111
|
if File.exist?(path)
|
108
112
|
File.foreach(path) { |line| yield(line) }
|
109
113
|
end
|
110
|
-
rescue => error
|
111
|
-
warn "
|
114
|
+
rescue SystemCallError => error
|
115
|
+
warn "Unable to read history file: #{error.message}"
|
112
116
|
end
|
113
117
|
|
114
118
|
# The default pusher. Appends the given line to Readline::HISTORY.
|
@@ -132,17 +136,26 @@ class Pry
|
|
132
136
|
if defined?(@history_file)
|
133
137
|
@history_file
|
134
138
|
else
|
139
|
+
unless File.exist?(history_file_path)
|
140
|
+
FileUtils.mkdir_p(File.dirname(history_file_path))
|
141
|
+
end
|
135
142
|
@history_file = File.open(history_file_path, 'a', 0600).tap do |file|
|
136
143
|
file.sync = true
|
137
144
|
end
|
138
145
|
end
|
139
|
-
rescue
|
140
|
-
warn
|
146
|
+
rescue SystemCallError => error
|
147
|
+
warn "Unable to write history file: #{error.message}"
|
141
148
|
@history_file = false
|
142
149
|
end
|
143
150
|
|
144
151
|
def history_file_path
|
145
152
|
File.expand_path(@file_path || Pry.config.history.file)
|
146
153
|
end
|
154
|
+
|
155
|
+
def invalid_readline_line?(line)
|
156
|
+
# `Readline::HISTORY << line` raises an `ArgumentError` if `line`
|
157
|
+
# includes a null byte
|
158
|
+
line.include?("\0")
|
159
|
+
end
|
147
160
|
end
|
148
161
|
end
|
data/lib/pry/hooks.rb
CHANGED
@@ -15,7 +15,7 @@ class Pry
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Ensure that duplicates have their @hooks object.
|
18
|
-
def initialize_copy(
|
18
|
+
def initialize_copy(_orig)
|
19
19
|
hooks_dup = @hooks.dup
|
20
20
|
@hooks.each do |k, v|
|
21
21
|
hooks_dup[k] = v.dup
|
@@ -32,7 +32,7 @@ class Pry
|
|
32
32
|
#
|
33
33
|
# @param [Pry::Hooks] other The `Pry::Hooks` instance to merge
|
34
34
|
# @return [Pry:Hooks] The receiver.
|
35
|
-
# @see
|
35
|
+
# @see #merge
|
36
36
|
def merge!(other)
|
37
37
|
@hooks.merge!(other.dup.hooks) do |key, array, other_array|
|
38
38
|
temp_hash, output = {}, []
|
@@ -65,7 +65,7 @@ class Pry
|
|
65
65
|
# @param [#call] callable The callable.
|
66
66
|
# @yield The block to use as the callable (if no `callable` provided).
|
67
67
|
# @return [Pry:Hooks] The receiver.
|
68
|
-
def add_hook(event_name, hook_name, callable=nil, &block)
|
68
|
+
def add_hook(event_name, hook_name, callable = nil, &block)
|
69
69
|
event_name = event_name.to_s
|
70
70
|
|
71
71
|
# do not allow duplicates, but allow multiple `nil` hooks
|
data/lib/pry/indent.rb
CHANGED
@@ -143,10 +143,9 @@ class Pry
|
|
143
143
|
prefix = indent_level
|
144
144
|
|
145
145
|
input.lines.each do |line|
|
146
|
-
|
147
146
|
if in_string?
|
148
147
|
tokens = tokenize("#{open_delimiters_line}\n#{line}")
|
149
|
-
tokens = tokens.drop_while{ |token, type| !(String === token && token.include?("\n")) }
|
148
|
+
tokens = tokens.drop_while { |token, type| !(String === token && token.include?("\n")) }
|
150
149
|
previously_in_string = true
|
151
150
|
else
|
152
151
|
tokens = tokenize(line)
|
@@ -155,7 +154,7 @@ class Pry
|
|
155
154
|
|
156
155
|
before, after = indentation_delta(tokens)
|
157
156
|
|
158
|
-
before.times{ prefix.sub! SPACES, '' }
|
157
|
+
before.times { prefix.sub! SPACES, '' }
|
159
158
|
new_prefix = prefix + SPACES * after
|
160
159
|
|
161
160
|
line = prefix + line.lstrip unless previously_in_string
|
@@ -215,7 +214,7 @@ class Pry
|
|
215
214
|
# If the list of tokens contains a matching closing token the line should
|
216
215
|
# not be indented (and thus we should return true).
|
217
216
|
tokens.each do |token, kind|
|
218
|
-
is_singleline_if
|
217
|
+
is_singleline_if = (SINGLELINE_TOKENS.include?(token)) && end_of_statement?(last_token, last_kind)
|
219
218
|
is_optional_do = (token == "do" && seen_for_at.include?(add_after - 1))
|
220
219
|
|
221
220
|
last_token, last_kind = token, kind unless kind == :space
|
@@ -358,7 +357,7 @@ class Pry
|
|
358
357
|
#
|
359
358
|
# @param [String] token a token from Coderay
|
360
359
|
# @param [Symbol] kind the kind of that token
|
361
|
-
def track_module_nesting_end(token, kind
|
360
|
+
def track_module_nesting_end(token, kind = :keyword)
|
362
361
|
if kind == :keyword && (token == "class" || token == "module")
|
363
362
|
@module_nesting.pop
|
364
363
|
end
|
@@ -382,25 +381,24 @@ class Pry
|
|
382
381
|
# the correct indentation. Mostly useful for fixing 'end'.
|
383
382
|
#
|
384
383
|
# @param [String] prompt The user's prompt
|
385
|
-
# @param [String] code
|
386
|
-
# @param [
|
387
|
-
# the difference in length between the old line and the new one)
|
388
|
-
#
|
389
|
-
|
384
|
+
# @param [String] code The code the user just typed in
|
385
|
+
# @param [Integer] overhang The number of characters to erase afterwards (the
|
386
|
+
# the difference in length between the old line and the new one)
|
387
|
+
#
|
388
|
+
# @return [String] correctly indented line
|
389
|
+
def correct_indentation(prompt, code, overhang = 0)
|
390
390
|
prompt = prompt.delete("\001\002")
|
391
391
|
line_to_measure = Pry::Helpers::Text.strip_color(prompt) << code
|
392
392
|
whitespace = ' ' * overhang
|
393
393
|
|
394
|
-
|
395
|
-
|
396
|
-
cols = cols.to_i
|
397
|
-
lines = (cols != 0 ? (line_to_measure.length / cols + 1) : 1).to_i
|
394
|
+
cols = Terminal.width!
|
395
|
+
lines = cols == 0 ? 1 : (line_to_measure.length / cols + 1).to_i
|
398
396
|
|
399
|
-
if
|
400
|
-
move_up
|
397
|
+
if Helpers::Platform.windows_ansi?
|
398
|
+
move_up = "\e[#{lines}F"
|
401
399
|
move_down = "\e[#{lines}E"
|
402
400
|
else
|
403
|
-
move_up
|
401
|
+
move_up = "\e[#{lines}A\e[0G"
|
404
402
|
move_down = "\e[#{lines}B\e[0G"
|
405
403
|
end
|
406
404
|
|
data/lib/pry/input_completer.rb
CHANGED
@@ -34,7 +34,7 @@ class Pry::InputCompleter
|
|
34
34
|
"yield" ]
|
35
35
|
|
36
36
|
Operators = [
|
37
|
-
"%", "&", "*", "**", "+",
|
37
|
+
"%", "&", "*", "**", "+", "-", "/",
|
38
38
|
"<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
|
39
39
|
"[]", "[]=", "^", "!", "!=", "!~"
|
40
40
|
]
|
@@ -92,7 +92,7 @@ class Pry::InputCompleter
|
|
92
92
|
when SYMBOL_REGEXP # Symbol
|
93
93
|
if Symbol.respond_to?(:all_symbols)
|
94
94
|
sym = Regexp.quote($1)
|
95
|
-
candidates = Symbol.all_symbols.collect{|s| ":" << s.id2name}
|
95
|
+
candidates = Symbol.all_symbols.collect { |s| ":" << s.id2name }
|
96
96
|
candidates.grep(/^#{sym}/)
|
97
97
|
else
|
98
98
|
[]
|
@@ -100,7 +100,7 @@ class Pry::InputCompleter
|
|
100
100
|
when TOPLEVEL_LOOKUP_REGEXP # Absolute Constant or class methods
|
101
101
|
receiver = $1
|
102
102
|
candidates = Object.constants.collect(&:to_s)
|
103
|
-
candidates.grep(/^#{receiver}/).collect{|e| "::" << e}
|
103
|
+
candidates.grep(/^#{receiver}/).collect { |e| "::" << e }
|
104
104
|
when CONSTANT_REGEXP # Constant
|
105
105
|
message = $1
|
106
106
|
begin
|
@@ -120,7 +120,7 @@ class Pry::InputCompleter
|
|
120
120
|
rescue Pry::RescuableException
|
121
121
|
candidates = []
|
122
122
|
end
|
123
|
-
candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
|
123
|
+
candidates.grep(/^#{message}/).collect { |e| receiver + "::" + e }
|
124
124
|
when SYMBOL_METHOD_CALL_REGEXP # method call on a Symbol
|
125
125
|
receiver = $1
|
126
126
|
message = Regexp.quote($2)
|
@@ -167,10 +167,12 @@ class Pry::InputCompleter
|
|
167
167
|
end
|
168
168
|
else
|
169
169
|
# func1.func2
|
170
|
+
require 'set'
|
170
171
|
candidates = Set.new
|
171
172
|
to_ignore = ignored_modules
|
172
|
-
ObjectSpace.each_object(Module){|m|
|
173
|
+
ObjectSpace.each_object(Module) { |m|
|
173
174
|
next if (to_ignore.include?(m) rescue true)
|
175
|
+
|
174
176
|
# jruby doesn't always provide #instance_methods() on each
|
175
177
|
# object.
|
176
178
|
if m.respond_to?(:instance_methods)
|
@@ -195,7 +197,7 @@ class Pry::InputCompleter
|
|
195
197
|
if eval("respond_to?(:class_variables)", bind)
|
196
198
|
candidates += eval("class_variables", bind).collect(&:to_s)
|
197
199
|
end
|
198
|
-
candidates = (candidates|ReservedWords|custom_completions).grep(/^#{Regexp.quote(input)}/)
|
200
|
+
candidates = (candidates | ReservedWords | custom_completions).grep(/^#{Regexp.quote(input)}/)
|
199
201
|
candidates.collect(&path)
|
200
202
|
end
|
201
203
|
rescue Pry::RescuableException
|
@@ -220,7 +222,8 @@ class Pry::InputCompleter
|
|
220
222
|
# path is a proc that takes an input and builds a full path.
|
221
223
|
def build_path(input)
|
222
224
|
# check to see if the input is a regex
|
223
|
-
return proc {|i| i.to_s }, input if input[/\/\./]
|
225
|
+
return proc { |i| i.to_s }, input if input[/\/\./]
|
226
|
+
|
224
227
|
trailing_slash = input.end_with?('/')
|
225
228
|
contexts = input.chomp('/').split(/\//)
|
226
229
|
input = contexts[-1]
|
@@ -241,6 +244,7 @@ class Pry::InputCompleter
|
|
241
244
|
|
242
245
|
scanner = lambda do |m|
|
243
246
|
next if s.include?(m) # IRB::ExtendCommandBundle::EXCB recurses.
|
247
|
+
|
244
248
|
s << m
|
245
249
|
m.constants(false).each do |c|
|
246
250
|
value = m.const_get(c)
|
@@ -251,6 +255,7 @@ class Pry::InputCompleter
|
|
251
255
|
# FIXME: Add Pry here as well?
|
252
256
|
[:IRB, :SLex, :RubyLex, :RubyToken].each do |module_name|
|
253
257
|
next unless Object.const_defined?(module_name)
|
258
|
+
|
254
259
|
scanner.call(Object.const_get(module_name))
|
255
260
|
end
|
256
261
|
|
data/lib/pry/input_lock.rb
CHANGED
data/lib/pry/last_exception.rb
CHANGED
data/lib/pry/method.rb
CHANGED
@@ -39,7 +39,7 @@ class Pry
|
|
39
39
|
# contain any context.
|
40
40
|
# @return [Pry::Method, nil] A `Pry::Method` instance containing the requested
|
41
41
|
# method, or `nil` if name is `nil` or no method could be located matching the parameters.
|
42
|
-
def from_str(name, target=TOPLEVEL_BINDING, options={})
|
42
|
+
def from_str(name, target = TOPLEVEL_BINDING, options = {})
|
43
43
|
if name.nil?
|
44
44
|
nil
|
45
45
|
elsif name.to_s =~ /(.+)\#(\S+)\Z/
|
@@ -56,8 +56,8 @@ class Pry
|
|
56
56
|
elsif options[:methods]
|
57
57
|
from_obj(target.eval("self"), name, target)
|
58
58
|
else
|
59
|
-
from_str(name, target, :
|
60
|
-
from_str(name, target, :
|
59
|
+
from_str(name, target, instance: true) or
|
60
|
+
from_str(name, target, methods: true)
|
61
61
|
end
|
62
62
|
|
63
63
|
rescue Pry::RescuableException
|
@@ -101,7 +101,7 @@ class Pry
|
|
101
101
|
# @param [Symbol] method_type The type of method: :method or :instance_method
|
102
102
|
# @param [Binding] target The binding where the method is looked up.
|
103
103
|
# @return [Method, UnboundMethod] The 'refined' method object.
|
104
|
-
def lookup_method_via_binding(obj, method_name, method_type, target=TOPLEVEL_BINDING)
|
104
|
+
def lookup_method_via_binding(obj, method_name, method_type, target = TOPLEVEL_BINDING)
|
105
105
|
Pry.current[:obj] = obj
|
106
106
|
Pry.current[:name] = method_name
|
107
107
|
receiver = obj.is_a?(Module) ? "Module" : "Kernel"
|
@@ -118,7 +118,7 @@ class Pry
|
|
118
118
|
# @param [String] name
|
119
119
|
# @param [Binding] target The binding where the method is looked up.
|
120
120
|
# @return [Pry::Method, nil]
|
121
|
-
def from_class(klass, name, target=TOPLEVEL_BINDING)
|
121
|
+
def from_class(klass, name, target = TOPLEVEL_BINDING)
|
122
122
|
new(lookup_method_via_binding(klass, name, :instance_method, target)) rescue nil
|
123
123
|
end
|
124
124
|
alias from_module from_class
|
@@ -131,7 +131,7 @@ class Pry
|
|
131
131
|
# @param [String] name
|
132
132
|
# @param [Binding] target The binding where the method is looked up.
|
133
133
|
# @return [Pry::Method, nil]
|
134
|
-
def from_obj(obj, name, target=TOPLEVEL_BINDING)
|
134
|
+
def from_obj(obj, name, target = TOPLEVEL_BINDING)
|
135
135
|
new(lookup_method_via_binding(obj, name, :method, target)) rescue nil
|
136
136
|
end
|
137
137
|
|
@@ -139,10 +139,10 @@ class Pry
|
|
139
139
|
# @param [Class,Module] klass
|
140
140
|
# @param [Boolean] include_super Whether to include methods from ancestors.
|
141
141
|
# @return [Array[Pry::Method]]
|
142
|
-
def all_from_class(klass, include_super=true)
|
142
|
+
def all_from_class(klass, include_super = true)
|
143
143
|
%w(public protected private).flat_map do |visibility|
|
144
144
|
safe_send(klass, :"#{visibility}_instance_methods", include_super).map do |method_name|
|
145
|
-
new(safe_send(klass, :instance_method, method_name), :
|
145
|
+
new(safe_send(klass, :instance_method, method_name), visibility: visibility.to_sym)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
@@ -157,7 +157,7 @@ class Pry
|
|
157
157
|
#
|
158
158
|
# @return [Array[Pry::Method]]
|
159
159
|
#
|
160
|
-
def all_from_obj(obj, include_super=true)
|
160
|
+
def all_from_obj(obj, include_super = true)
|
161
161
|
all_from_class(singleton_class_of(obj), include_super)
|
162
162
|
end
|
163
163
|
|
@@ -166,7 +166,7 @@ class Pry
|
|
166
166
|
# please use {all_from_obj} instead.
|
167
167
|
# the `method_type` argument is ignored.
|
168
168
|
#
|
169
|
-
def all_from_common(obj,
|
169
|
+
def all_from_common(obj, _method_type = nil, include_super = true)
|
170
170
|
all_from_obj(obj, include_super)
|
171
171
|
end
|
172
172
|
|
@@ -233,7 +233,7 @@ class Pry
|
|
233
233
|
# @param [::Method, UnboundMethod, Proc] method
|
234
234
|
# @param [Hash] known_info Can be used to pre-cache expensive to compute stuff.
|
235
235
|
# @return [Pry::Method]
|
236
|
-
def initialize(method, known_info={})
|
236
|
+
def initialize(method, known_info = {})
|
237
237
|
@method = method
|
238
238
|
@visibility = known_info[:visibility]
|
239
239
|
end
|
@@ -298,7 +298,8 @@ class Pry
|
|
298
298
|
# @return [String, nil] The documentation for the method, or `nil` if it's
|
299
299
|
# unavailable.
|
300
300
|
def doc
|
301
|
-
@doc ||=
|
301
|
+
@doc ||=
|
302
|
+
case source_type
|
302
303
|
when :c
|
303
304
|
info = pry_doc_info
|
304
305
|
info.docstring if info
|
@@ -317,7 +318,7 @@ class Pry
|
|
317
318
|
# `nil` if the filename is unavailable.
|
318
319
|
def source_file
|
319
320
|
if source_location.nil?
|
320
|
-
if
|
321
|
+
if source_type == :c
|
321
322
|
info = pry_doc_info
|
322
323
|
info.file if info
|
323
324
|
end
|
@@ -354,20 +355,24 @@ class Pry
|
|
354
355
|
|
355
356
|
# @return [String] A representation of the method's signature, including its
|
356
357
|
# name and parameters. Optional and "rest" parameters are marked with `*`
|
357
|
-
# and block parameters with `&`.
|
358
|
-
# they're given numbered names instead.
|
358
|
+
# and block parameters with `&`. Keyword arguments are shown with `:`
|
359
|
+
# If the parameter names are unavailable, they're given numbered names instead.
|
359
360
|
# Paraphrased from `awesome_print` gem.
|
360
361
|
def signature
|
361
362
|
if respond_to?(:parameters)
|
362
|
-
args = parameters.inject([]) do |
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
363
|
+
args = parameters.inject([]) do |args_array, (arg_type, name)|
|
364
|
+
name ||= (arg_type == :block ? 'block' : "arg#{args_array.size + 1}")
|
365
|
+
args_array.push(
|
366
|
+
case arg_type
|
367
|
+
when :req then name.to_s
|
368
|
+
when :opt then "#{name}=?"
|
369
|
+
when :rest then "*#{name}"
|
370
|
+
when :block then "&#{name}"
|
371
|
+
when :key then "#{name}:?"
|
372
|
+
when :keyreq then "#{name}:"
|
373
|
+
else '?'
|
374
|
+
end
|
375
|
+
)
|
371
376
|
end
|
372
377
|
else
|
373
378
|
args = (1..arity.abs).map { |i| "arg#{i}" }
|
@@ -379,7 +384,7 @@ class Pry
|
|
379
384
|
|
380
385
|
# @return [Pry::Method, nil] The wrapped method that is called when you
|
381
386
|
# use "super" in the body of this method.
|
382
|
-
def super(times=1)
|
387
|
+
def super(times = 1)
|
383
388
|
if UnboundMethod === @method
|
384
389
|
sup = super_using_ancestors(Pry::Method.instance_resolution_order(owner), times)
|
385
390
|
else
|
@@ -393,6 +398,7 @@ class Pry
|
|
393
398
|
# before any aliasing, or `nil` if it can't be determined.
|
394
399
|
def original_name
|
395
400
|
return nil if source_type != :ruby
|
401
|
+
|
396
402
|
method_name_from_first_line(source.lines.first)
|
397
403
|
end
|
398
404
|
|
@@ -461,7 +467,7 @@ class Pry
|
|
461
467
|
|
462
468
|
# @param [String, Symbol] method_name
|
463
469
|
# @return [Boolean]
|
464
|
-
def respond_to?(method_name, include_all=false)
|
470
|
+
def respond_to?(method_name, include_all = false)
|
465
471
|
super or @method.respond_to?(method_name, include_all)
|
466
472
|
end
|
467
473
|
|
@@ -483,7 +489,7 @@ class Pry
|
|
483
489
|
Pry::MethodInfo.info_for(@method) or raise CommandError, "Cannot locate this method: #{name}. (source_location returns nil)"
|
484
490
|
else
|
485
491
|
fail_msg = "Cannot locate this method: #{name}."
|
486
|
-
if mri?
|
492
|
+
if Helpers::Platform.mri?
|
487
493
|
fail_msg += " Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.\n"
|
488
494
|
end
|
489
495
|
raise CommandError, fail_msg
|
@@ -492,7 +498,7 @@ class Pry
|
|
492
498
|
|
493
499
|
# @param [Class, Module] ancestors The ancestors to investigate
|
494
500
|
# @return [Method] The unwrapped super-method
|
495
|
-
def super_using_ancestors(ancestors, times=1)
|
501
|
+
def super_using_ancestors(ancestors, times = 1)
|
496
502
|
next_owner = self.owner
|
497
503
|
times.times do
|
498
504
|
i = ancestors.index(next_owner) + 1
|
@@ -529,9 +535,9 @@ class Pry
|
|
529
535
|
end
|
530
536
|
|
531
537
|
def ruby_source
|
532
|
-
#
|
533
|
-
# hacked version of source_location for
|
534
|
-
#
|
538
|
+
# Clone of `MethodSource.source_helper` that knows to use our
|
539
|
+
# hacked version of `source_location` for our input buffer for methods
|
540
|
+
# defined in `(pry)`.
|
535
541
|
file, line = *source_location
|
536
542
|
raise SourceNotFoundError, "Could not locate source for #{name_with_owner}!" unless file
|
537
543
|
|