pry 0.12.2-java → 0.13.0-java
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 +110 -1
- data/LICENSE +1 -1
- data/README.md +331 -269
- data/bin/pry +5 -0
- data/lib/pry.rb +133 -119
- data/lib/pry/basic_object.rb +8 -4
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +40 -31
- data/lib/pry/code.rb +39 -27
- data/lib/pry/code/code_file.rb +28 -24
- data/lib/pry/code/code_range.rb +4 -2
- data/lib/pry/code/loc.rb +15 -8
- data/lib/pry/code_object.rb +40 -38
- data/lib/pry/color_printer.rb +47 -46
- data/lib/pry/command.rb +166 -369
- data/lib/pry/command_set.rb +76 -73
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -81
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat.rb +61 -54
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +71 -60
- data/lib/pry/commands/cat/file_formatter.rb +55 -49
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +44 -39
- data/lib/pry/commands/clear_screen.rb +16 -10
- data/lib/pry/commands/code_collector.rb +148 -133
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +19 -30
- data/lib/pry/commands/edit.rb +184 -161
- 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/exit.rb +39 -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 -160
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -150
- data/lib/pry/commands/import_set.rb +20 -16
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls.rb +124 -102
- data/lib/pry/commands/ls/constants.rb +59 -42
- data/lib/pry/commands/ls/formatter.rb +50 -46
- data/lib/pry/commands/ls/globals.rb +38 -34
- data/lib/pry/commands/ls/grep.rb +17 -13
- data/lib/pry/commands/ls/instance_vars.rb +29 -27
- 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 -22
- data/lib/pry/commands/ls/local_vars.rb +38 -28
- data/lib/pry/commands/ls/ls_entity.rb +47 -51
- data/lib/pry/commands/ls/methods.rb +44 -43
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -22
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -82
- data/lib/pry/commands/pry_backtrace.rb +24 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +27 -22
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +55 -45
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +51 -51
- data/lib/pry/commands/shell_mode.rb +21 -17
- data/lib/pry/commands/show_doc.rb +81 -68
- data/lib/pry/commands/show_info.rb +189 -171
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +109 -45
- 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.rb +89 -86
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/whereami.rb +156 -148
- data/lib/pry/commands/wtf.rb +75 -50
- data/lib/pry/config.rb +311 -25
- 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/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +9 -7
- data/lib/pry/editor.rb +48 -21
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -16
- data/lib/pry/forwardable.rb +5 -1
- data/lib/pry/helpers.rb +2 -0
- data/lib/pry/helpers/base_helpers.rb +68 -197
- data/lib/pry/helpers/command_helpers.rb +50 -61
- data/lib/pry/helpers/documentation_helpers.rb +20 -13
- data/lib/pry/helpers/options_helpers.rb +14 -7
- data/lib/pry/helpers/platform.rb +7 -5
- data/lib/pry/helpers/table.rb +33 -26
- data/lib/pry/helpers/text.rb +17 -14
- data/lib/pry/history.rb +48 -56
- data/lib/pry/hooks.rb +21 -12
- data/lib/pry/indent.rb +54 -50
- data/lib/pry/input_completer.rb +248 -230
- data/lib/pry/input_lock.rb +8 -9
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method.rb +141 -94
- data/lib/pry/method/disowned.rb +16 -4
- data/lib/pry/method/patcher.rb +12 -3
- data/lib/pry/method/weird_method_locator.rb +68 -44
- data/lib/pry/object_path.rb +33 -25
- data/lib/pry/output.rb +121 -35
- data/lib/pry/pager.rb +41 -42
- data/lib/pry/plugins.rb +25 -8
- data/lib/pry/prompt.rb +123 -54
- data/lib/pry/pry_class.rb +61 -98
- data/lib/pry/pry_instance.rb +217 -215
- data/lib/pry/repl.rb +18 -22
- data/lib/pry/repl_file_loader.rb +27 -21
- data/lib/pry/ring.rb +11 -6
- data/lib/pry/slop.rb +574 -563
- data/lib/pry/slop/commands.rb +164 -169
- data/lib/pry/slop/option.rb +172 -168
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable.rb +59 -61
- data/lib/pry/testable/evalable.rb +21 -12
- data/lib/pry/testable/mockable.rb +18 -10
- data/lib/pry/testable/pry_tester.rb +71 -56
- data/lib/pry/testable/utility.rb +29 -21
- data/lib/pry/testable/variables.rb +49 -43
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +27 -0
- data/lib/pry/wrapped_module.rb +51 -42
- data/lib/pry/wrapped_module/candidate.rb +21 -14
- metadata +31 -30
- data/lib/pry/commands.rb +0 -6
- 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/gem_readme.rb +0 -25
- data/lib/pry/commands/gem_search.rb +0 -40
- data/lib/pry/commands/gem_stats.rb +0 -83
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -54
- data/lib/pry/config/behavior.rb +0 -255
- data/lib/pry/config/convenience.rb +0 -28
- data/lib/pry/config/default.rb +0 -159
- data/lib/pry/config/memoization.rb +0 -48
- data/lib/pry/platform.rb +0 -91
- data/lib/pry/rubygem.rb +0 -84
- data/lib/pry/terminal.rb +0 -91
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'coderay'
|
4
|
+
|
5
|
+
class Pry
|
6
|
+
# @api private
|
7
|
+
# @since v0.13.0
|
8
|
+
class SyntaxHighlighter
|
9
|
+
def self.highlight(code, language = :ruby)
|
10
|
+
tokenize(code, language).term
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.tokenize(code, language = :ruby)
|
14
|
+
CodeRay.scan(code, language)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.keyword_token_color
|
18
|
+
CodeRay::Encoders::Terminal::TOKEN_COLORS[:keyword]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Sets comment token to blue (black by default), so it's more legible.
|
22
|
+
def self.overwrite_coderay_comment_token!
|
23
|
+
CodeRay::Encoders::Terminal::TOKEN_COLORS[:comment][:self] = "\e[1;34m"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
# @api private
|
5
|
+
# @since v0.13.0
|
6
|
+
module SystemCommandHandler
|
7
|
+
class << self
|
8
|
+
def default(output, command, _pry_instance)
|
9
|
+
return if Kernel.system(command)
|
10
|
+
|
11
|
+
output.puts(
|
12
|
+
"Error: there was a problem executing system command: #{command}"
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/pry/testable.rb
CHANGED
@@ -1,70 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# good idea ???
|
2
4
|
# if you're testing pry plugin you should require pry by yourself, no?
|
3
|
-
require 'pry'
|
5
|
+
require 'pry' unless defined?(Pry)
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class Pry
|
8
|
+
module Testable
|
9
|
+
require_relative "testable/pry_tester"
|
10
|
+
require_relative "testable/evalable"
|
11
|
+
require_relative "testable/mockable"
|
12
|
+
require_relative "testable/variables"
|
13
|
+
require_relative "testable/utility"
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
15
|
+
#
|
16
|
+
# When {Pry::Testable} is included into another module or class,
|
17
|
+
# the following modules are also included: {Pry::Testable::Mockable},
|
18
|
+
# {Pry::Testable::Evalable}, {Pry::Testable::Variables}, and
|
19
|
+
# {Pry::Testable::Utility}.
|
20
|
+
#
|
21
|
+
# @note
|
22
|
+
# Each of the included modules mentioned above may also be used
|
23
|
+
# standalone or in a pick-and-mix fashion.
|
24
|
+
#
|
25
|
+
# @param [Module] mod
|
26
|
+
# A class or module.
|
27
|
+
#
|
28
|
+
# @return [void]
|
29
|
+
#
|
30
|
+
def self.included(mod)
|
31
|
+
mod.module_eval do
|
32
|
+
include Pry::Testable::Mockable
|
33
|
+
include Pry::Testable::Evalable
|
34
|
+
include Pry::Testable::Variables
|
35
|
+
include Pry::Testable::Utility
|
36
|
+
end
|
34
37
|
end
|
35
|
-
end
|
36
|
-
|
37
|
-
TEST_DEFAULTS = {
|
38
|
-
color: false,
|
39
|
-
pager: false,
|
40
|
-
should_load_rc: false,
|
41
|
-
should_load_local_rc: false,
|
42
|
-
correct_indent: false,
|
43
|
-
collison_warning: false,
|
44
|
-
history: {
|
45
|
-
should_load: false,
|
46
|
-
should_save: false
|
47
|
-
}
|
48
|
-
}
|
49
|
-
private_constant :TEST_DEFAULTS
|
50
38
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
39
|
+
#
|
40
|
+
# Sets various configuration options that make Pry optimal for a test
|
41
|
+
# environment, see source code for complete details.
|
42
|
+
#
|
43
|
+
# @return [void]
|
44
|
+
#
|
45
|
+
def self.set_testenv_variables
|
46
|
+
Pry.config = Pry::Config.new.merge(
|
47
|
+
color: false,
|
48
|
+
pager: false,
|
49
|
+
should_load_rc: false,
|
50
|
+
should_load_local_rc: false,
|
51
|
+
correct_indent: false,
|
52
|
+
collision_warning: false,
|
53
|
+
history_save: false,
|
54
|
+
history_load: false,
|
55
|
+
hooks: Pry::Hooks.new
|
56
|
+
)
|
57
|
+
end
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
59
|
+
#
|
60
|
+
# Reset the Pry configuration to their default values.
|
61
|
+
#
|
62
|
+
# @return [void]
|
63
|
+
#
|
64
|
+
def self.unset_testenv_variables
|
65
|
+
Pry.config = Pry::Config.new
|
66
|
+
end
|
69
67
|
end
|
70
68
|
end
|
@@ -1,15 +1,24 @@
|
|
1
|
-
|
2
|
-
def pry_tester(*args, &block)
|
3
|
-
if args.length == 0 || args[0].is_a?(Hash)
|
4
|
-
args.unshift(Pry.toplevel_binding)
|
5
|
-
end
|
6
|
-
Pry::Testable::PryTester.new(*args).tap do |t|
|
7
|
-
t.singleton_class.class_eval(&block) if block
|
8
|
-
end
|
9
|
-
end
|
1
|
+
# frozen_string_literal: true
|
10
2
|
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
class Pry
|
4
|
+
module Testable
|
5
|
+
module Evalable
|
6
|
+
def pry_tester(*args, &block)
|
7
|
+
args.unshift(Pry.toplevel_binding) if args.empty? || args[0].is_a?(Hash)
|
8
|
+
Pry::Testable::PryTester.new(*args).tap do |t|
|
9
|
+
t.singleton_class.class_eval(&block) if block
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def pry_eval(*eval_strs)
|
14
|
+
b =
|
15
|
+
if eval_strs.first.is_a?(String)
|
16
|
+
Pry.toplevel_binding
|
17
|
+
else
|
18
|
+
Pry.binding_for(eval_strs.shift)
|
19
|
+
end
|
20
|
+
pry_tester(b).eval(*eval_strs)
|
21
|
+
end
|
22
|
+
end
|
14
23
|
end
|
15
24
|
end
|
@@ -1,14 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class Pry
|
6
|
+
module Testable
|
7
|
+
module Mockable
|
8
|
+
def mock_command(cmd, args = [], opts = {})
|
9
|
+
output = StringIO.new
|
10
|
+
pry = Pry.new(output: output)
|
11
|
+
ret = cmd.new(opts.merge(pry_instance: pry, output: output)).call_safely(*args)
|
12
|
+
Struct.new(:output, :return).new(output.string, ret)
|
13
|
+
end
|
8
14
|
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
def mock_exception(*mock_backtrace)
|
16
|
+
StandardError.new.tap do |e|
|
17
|
+
e.define_singleton_method(:backtrace) { mock_backtrace }
|
18
|
+
end
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
14
22
|
end
|
@@ -1,73 +1,88 @@
|
|
1
|
-
|
2
|
-
extend Pry::Forwardable
|
3
|
-
attr_reader :pry, :out
|
4
|
-
def_delegators :@pry, :eval_string, :eval_string=
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
@pry = Pry.new(options.merge(target: target))
|
8
|
-
@history = options[:history]
|
9
|
-
@pry.inject_sticky_locals!
|
10
|
-
reset_output
|
11
|
-
end
|
3
|
+
require 'stringio'
|
12
4
|
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
class Pry
|
6
|
+
module Testable
|
7
|
+
class PryTester
|
8
|
+
extend Pry::Forwardable
|
9
|
+
attr_reader :pry, :out
|
10
|
+
def_delegators :@pry, :eval_string, :eval_string=
|
16
11
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
def initialize(target = TOPLEVEL_BINDING, options = {})
|
13
|
+
@pry = Pry.new(options.merge(target: target))
|
14
|
+
@history = options[:history]
|
15
|
+
@pry.inject_sticky_locals!
|
16
|
+
reset_output
|
21
17
|
end
|
22
|
-
@history.push str if @history
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
def eval(*strs)
|
20
|
+
reset_output
|
21
|
+
result = nil
|
22
|
+
|
23
|
+
strs.flatten.each do |str|
|
24
|
+
# Check for space prefix. See #1369.
|
25
|
+
str = "#{str.strip}\n" if str !~ /^\s\S/
|
26
|
+
@history.push str if @history
|
27
|
+
|
28
|
+
result =
|
29
|
+
if @pry.process_command(str)
|
30
|
+
last_command_result_or_output
|
31
|
+
else
|
32
|
+
# Check if this is a multiline paste.
|
33
|
+
begin
|
34
|
+
complete_expr = Pry::Code.complete_expression?(str)
|
35
|
+
rescue SyntaxError => exception
|
36
|
+
@pry.output.puts(
|
37
|
+
"SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}"
|
38
|
+
)
|
39
|
+
end
|
40
|
+
@pry.evaluate_ruby(str) if complete_expr
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
result
|
28
45
|
end
|
29
|
-
end
|
30
46
|
|
31
|
-
|
32
|
-
|
47
|
+
def push(*lines)
|
48
|
+
Array(lines).flatten.each do |line|
|
49
|
+
@pry.eval(line)
|
50
|
+
end
|
51
|
+
end
|
33
52
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
53
|
+
def push_binding(context)
|
54
|
+
@pry.push_binding context
|
55
|
+
end
|
39
56
|
|
40
|
-
|
41
|
-
|
42
|
-
|
57
|
+
def last_output
|
58
|
+
@out.string if @out
|
59
|
+
end
|
43
60
|
|
44
|
-
|
45
|
-
|
46
|
-
|
61
|
+
def process_command(command_str)
|
62
|
+
@pry.process_command(command_str) || raise("Not a valid command")
|
63
|
+
last_command_result_or_output
|
64
|
+
end
|
47
65
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
66
|
+
def last_command_result
|
67
|
+
result = Pry.current[:pry_cmd_result]
|
68
|
+
result.retval if result
|
69
|
+
end
|
52
70
|
|
53
|
-
|
54
|
-
result = Pry.current[:pry_cmd_result]
|
55
|
-
result.retval if result
|
56
|
-
end
|
71
|
+
protected
|
57
72
|
|
58
|
-
|
73
|
+
def last_command_result_or_output
|
74
|
+
result = last_command_result
|
75
|
+
if result != Pry::Command::VOID_VALUE
|
76
|
+
result
|
77
|
+
else
|
78
|
+
last_output
|
79
|
+
end
|
80
|
+
end
|
59
81
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
else
|
65
|
-
last_output
|
82
|
+
def reset_output
|
83
|
+
@out = StringIO.new
|
84
|
+
@pry.output = @out
|
85
|
+
end
|
66
86
|
end
|
67
87
|
end
|
68
|
-
|
69
|
-
def reset_output
|
70
|
-
@out = StringIO.new
|
71
|
-
@pry.output = @out
|
72
|
-
end
|
73
88
|
end
|
data/lib/pry/testable/utility.rb
CHANGED
@@ -1,26 +1,34 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Creates a Tempfile then unlinks it after the block has yielded.
|
4
|
-
#
|
5
|
-
# @yieldparam [String] file
|
6
|
-
# The path of the temp file
|
7
|
-
#
|
8
|
-
# @return [void]
|
9
|
-
#
|
10
|
-
def temp_file(ext = '.rb')
|
11
|
-
file = Tempfile.open(['pry', ext])
|
12
|
-
yield file
|
13
|
-
ensure
|
14
|
-
file.close(true) if file
|
15
|
-
end
|
1
|
+
# frozen_string_literal: true
|
16
2
|
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
class Pry
|
6
|
+
module Testable
|
7
|
+
module Utility
|
8
|
+
#
|
9
|
+
# Creates a Tempfile then unlinks it after the block has yielded.
|
10
|
+
#
|
11
|
+
# @yieldparam [String] file
|
12
|
+
# The path of the temp file
|
13
|
+
#
|
14
|
+
# @return [void]
|
15
|
+
#
|
16
|
+
def temp_file(ext = '.rb')
|
17
|
+
file = Tempfile.open(['pry', ext])
|
18
|
+
yield file
|
19
|
+
ensure
|
20
|
+
file.close(true) if file
|
21
|
+
end
|
22
|
+
|
23
|
+
def unindent(*args)
|
24
|
+
Pry::Helpers::CommandHelpers.unindent(*args)
|
25
|
+
end
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
def inner_scope
|
28
|
+
catch(:inner_scope) do
|
29
|
+
yield -> { throw(:inner_scope, self) }
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
@@ -1,46 +1,52 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# @example
|
4
|
-
# temporary_constants(:Foo, :Bar) do
|
5
|
-
# Foo = Class.new(RuntimeError)
|
6
|
-
# Bar = Class.new(RuntimeError)
|
7
|
-
# end
|
8
|
-
# Foo # => NameError
|
9
|
-
# Bar # => NameError
|
10
|
-
#
|
11
|
-
# @param [Array<Symbol>] names
|
12
|
-
# An array of constant names that be defined by a block,
|
13
|
-
# and removed by this method afterwards.
|
14
|
-
#
|
15
|
-
# @return [void]
|
16
|
-
#
|
17
|
-
def temporary_constants(*names)
|
18
|
-
names.each do |name|
|
19
|
-
Object.remove_const name if Object.const_defined?(name)
|
20
|
-
end
|
21
|
-
yield
|
22
|
-
ensure
|
23
|
-
names.each do |name|
|
24
|
-
Object.remove_const name if Object.const_defined?(name)
|
25
|
-
end
|
26
|
-
end
|
1
|
+
# frozen_string_literal: true
|
27
2
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
3
|
+
class Pry
|
4
|
+
module Testable
|
5
|
+
module Variables
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# temporary_constants(:Foo, :Bar) do
|
9
|
+
# Foo = Class.new(RuntimeError)
|
10
|
+
# Bar = Class.new(RuntimeError)
|
11
|
+
# end
|
12
|
+
# Foo # => NameError
|
13
|
+
# Bar # => NameError
|
14
|
+
#
|
15
|
+
# @param [Array<Symbol>] names
|
16
|
+
# An array of constant names that be defined by a block,
|
17
|
+
# and removed by this method afterwards.
|
18
|
+
#
|
19
|
+
# @return [void]
|
20
|
+
#
|
21
|
+
def temporary_constants(*names)
|
22
|
+
names.each do |name|
|
23
|
+
Object.remove_const name if Object.const_defined?(name)
|
24
|
+
end
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
names.each do |name|
|
28
|
+
Object.remove_const name if Object.const_defined?(name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# @param [String] name
|
34
|
+
# The name of a variable.
|
35
|
+
#
|
36
|
+
# @param [String] value
|
37
|
+
# Its value.
|
38
|
+
#
|
39
|
+
# @param [Binding] binding
|
40
|
+
# The binding object to insert a variable into.
|
41
|
+
#
|
42
|
+
# @return [void]
|
43
|
+
#
|
44
|
+
def insert_variable(name, value, binding)
|
45
|
+
Pry.current[:pry_local] = value
|
46
|
+
binding.eval("#{name} = ::Pry.current[:pry_local]")
|
47
|
+
ensure
|
48
|
+
Pry.current[:pry_local] = nil
|
49
|
+
end
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|