pry 0.11.3 → 0.12.0

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 +5 -5
  2. data/CHANGELOG.md +139 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry.rb +17 -47
  7. data/lib/pry/cli.rb +17 -24
  8. data/lib/pry/code.rb +6 -6
  9. data/lib/pry/code/code_file.rb +5 -4
  10. data/lib/pry/code/code_range.rb +3 -3
  11. data/lib/pry/code/loc.rb +14 -8
  12. data/lib/pry/code_object.rb +4 -4
  13. data/lib/pry/color_printer.rb +1 -0
  14. data/lib/pry/command.rb +36 -29
  15. data/lib/pry/command_set.rb +17 -52
  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.rb +7 -6
  19. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/change_prompt.rb +29 -9
  22. data/lib/pry/commands/clear_screen.rb +14 -0
  23. data/lib/pry/commands/code_collector.rb +9 -9
  24. data/lib/pry/commands/easter_eggs.rb +3 -3
  25. data/lib/pry/commands/edit.rb +8 -7
  26. data/lib/pry/commands/exit.rb +2 -1
  27. data/lib/pry/commands/find_method.rb +11 -13
  28. data/lib/pry/commands/gem_cd.rb +1 -1
  29. data/lib/pry/commands/gem_install.rb +2 -2
  30. data/lib/pry/commands/gem_list.rb +2 -2
  31. data/lib/pry/commands/gem_open.rb +1 -1
  32. data/lib/pry/commands/gem_search.rb +2 -2
  33. data/lib/pry/commands/gem_stats.rb +83 -0
  34. data/lib/pry/commands/gist.rb +7 -6
  35. data/lib/pry/commands/help.rb +3 -3
  36. data/lib/pry/commands/hist.rb +9 -8
  37. data/lib/pry/commands/import_set.rb +2 -1
  38. data/lib/pry/commands/install_command.rb +7 -6
  39. data/lib/pry/commands/list_inspectors.rb +2 -2
  40. data/lib/pry/commands/ls.rb +27 -30
  41. data/lib/pry/commands/ls/constants.rb +4 -4
  42. data/lib/pry/commands/ls/formatter.rb +3 -2
  43. data/lib/pry/commands/ls/globals.rb +0 -2
  44. data/lib/pry/commands/ls/grep.rb +0 -2
  45. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  46. data/lib/pry/commands/ls/local_names.rb +0 -2
  47. data/lib/pry/commands/ls/local_vars.rb +0 -2
  48. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  49. data/lib/pry/commands/ls/methods.rb +0 -3
  50. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  51. data/lib/pry/commands/ls/self_methods.rb +0 -1
  52. data/lib/pry/commands/play.rb +1 -2
  53. data/lib/pry/commands/pry_backtrace.rb +1 -1
  54. data/lib/pry/commands/raise_up.rb +2 -1
  55. data/lib/pry/commands/ri.rb +5 -4
  56. data/lib/pry/commands/shell_command.rb +3 -2
  57. data/lib/pry/commands/shell_mode.rb +6 -6
  58. data/lib/pry/commands/show_doc.rb +5 -7
  59. data/lib/pry/commands/show_info.rb +25 -18
  60. data/lib/pry/commands/show_source.rb +5 -2
  61. data/lib/pry/commands/stat.rb +1 -1
  62. data/lib/pry/commands/watch_expression.rb +9 -7
  63. data/lib/pry/commands/whereami.rb +4 -4
  64. data/lib/pry/commands/wtf.rb +15 -2
  65. data/lib/pry/config.rb +33 -9
  66. data/lib/pry/config/behavior.rb +229 -205
  67. data/lib/pry/config/convenience.rb +24 -21
  68. data/lib/pry/config/default.rb +153 -143
  69. data/lib/pry/config/memoization.rb +41 -37
  70. data/lib/pry/core_extensions.rb +4 -3
  71. data/lib/pry/editor.rb +5 -12
  72. data/lib/pry/exceptions.rb +0 -2
  73. data/lib/pry/helpers.rb +1 -0
  74. data/lib/pry/helpers/base_helpers.rb +133 -4
  75. data/lib/pry/helpers/command_helpers.rb +5 -4
  76. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  77. data/lib/pry/helpers/options_helpers.rb +5 -5
  78. data/lib/pry/helpers/platform.rb +58 -0
  79. data/lib/pry/helpers/table.rb +20 -15
  80. data/lib/pry/helpers/text.rb +3 -4
  81. data/lib/pry/history.rb +21 -8
  82. data/lib/pry/hooks.rb +3 -3
  83. data/lib/pry/indent.rb +15 -17
  84. data/lib/pry/input_completer.rb +12 -7
  85. data/lib/pry/input_lock.rb +0 -2
  86. data/lib/pry/last_exception.rb +1 -1
  87. data/lib/pry/method.rb +37 -31
  88. data/lib/pry/method/disowned.rb +2 -1
  89. data/lib/pry/method/patcher.rb +2 -2
  90. data/lib/pry/method/weird_method_locator.rb +7 -8
  91. data/lib/pry/object_path.rb +5 -4
  92. data/lib/pry/output.rb +3 -2
  93. data/lib/pry/pager.rb +4 -3
  94. data/lib/pry/platform.rb +79 -81
  95. data/lib/pry/plugins.rb +7 -3
  96. data/lib/pry/prompt.rb +144 -25
  97. data/lib/pry/pry_class.rb +53 -29
  98. data/lib/pry/pry_instance.rb +88 -55
  99. data/lib/pry/repl.rb +33 -4
  100. data/lib/pry/repl_file_loader.rb +1 -2
  101. data/lib/pry/ring.rb +84 -0
  102. data/lib/pry/rubygem.rb +6 -6
  103. data/lib/pry/slop.rb +17 -17
  104. data/lib/pry/slop/commands.rb +3 -4
  105. data/lib/pry/slop/option.rb +19 -21
  106. data/lib/pry/terminal.rb +2 -1
  107. data/lib/pry/testable/mockable.rb +2 -2
  108. data/lib/pry/testable/pry_tester.rb +1 -1
  109. data/lib/pry/testable/utility.rb +2 -2
  110. data/lib/pry/testable/variables.rb +1 -1
  111. data/lib/pry/version.rb +1 -1
  112. data/lib/pry/wrapped_module.rb +15 -15
  113. data/lib/pry/wrapped_module/candidate.rb +2 -2
  114. metadata +17 -29
  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
@@ -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)
@@ -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
 
@@ -338,7 +338,7 @@ class Pry
338
338
  undef =~
339
339
 
340
340
  # Check whether String responds to missing methods.
341
- def respond_to_missing?(name, include_all=false)
341
+ def respond_to_missing?(name, include_all = false)
342
342
  ''.respond_to?(name, include_all)
343
343
  end
344
344
 
@@ -25,6 +25,10 @@ class Pry
25
25
  %w(Gemfile Rakefile Guardfile Capfile) => :ruby
26
26
  }
27
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
+
28
32
  # @return [Symbol] The type of code stored in this wrapper.
29
33
  attr_reader :code_type
30
34
 
@@ -41,8 +45,6 @@ class Pry
41
45
  Pry.line_buffer.drop(1)
42
46
  elsif Pry::Method::Patcher.code_for(@filename)
43
47
  Pry::Method::Patcher.code_for(@filename)
44
- elsif RbxPath.is_core_path?(@filename)
45
- File.read(RbxPath.convert_path_to_full(@filename))
46
48
  else
47
49
  path = abs_path
48
50
  @code_type = type_from_filename(path)
@@ -97,13 +99,12 @@ class Pry
97
99
 
98
100
  # @return [String]
99
101
  def from_pry_init_pwd
100
- File.expand_path(@filename, Pry::INITIAL_PWD)
102
+ File.expand_path(@filename, INITIAL_PWD)
101
103
  end
102
104
 
103
105
  # @return [String]
104
106
  def from_load_path
105
107
  $LOAD_PATH.map { |path| File.expand_path(@filename, path) }
106
108
  end
107
-
108
109
  end
109
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
@@ -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
@@ -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
@@ -64,7 +63,7 @@ class Pry
64
63
  include Pry::Helpers::CommandHelpers
65
64
 
66
65
  class << self
67
- def lookup(str, _pry_, options={})
66
+ def lookup(str, _pry_, options = {})
68
67
  co = new(str, _pry_, options)
69
68
 
70
69
  co.default_lookup || co.method_or_class_lookup ||
@@ -77,9 +76,9 @@ class Pry
77
76
  attr_accessor :_pry_
78
77
  attr_accessor :super_level
79
78
 
80
- def initialize(str, _pry_, options={})
79
+ def initialize(str, _pry_, options = {})
81
80
  options = {
82
- :super => 0,
81
+ super: 0,
83
82
  }.merge!(options)
84
83
 
85
84
  @str = str
@@ -170,6 +169,7 @@ class Pry
170
169
  def safe_to_evaluate?(str)
171
170
  return true if str.strip == "self"
172
171
  return false if str =~ /%/
172
+
173
173
  kind = target.eval("defined?(#{str})")
174
174
  kind =~ /variable|constant/
175
175
  end
@@ -40,6 +40,7 @@ class Pry
40
40
  end
41
41
  rescue => e
42
42
  raise if e.is_a? Pry::Pager::StopPaging
43
+
43
44
  begin
44
45
  str = obj.inspect
45
46
  rescue Exception
@@ -2,7 +2,6 @@ require 'delegate'
2
2
  require 'pry/helpers/documentation_helpers'
3
3
 
4
4
  class Pry
5
-
6
5
  # The super-class of all commands, new commands should be created by calling
7
6
  # {Pry::CommandSet#command} which creates a BlockCommand or {Pry::CommandSet#create_command}
8
7
  # which creates a ClassCommand. Please don't use this class directly.
@@ -24,7 +23,7 @@ class Pry
24
23
  attr_writer :command_options
25
24
  attr_writer :match
26
25
 
27
- def match(arg=nil)
26
+ def match(arg = nil)
28
27
  if arg
29
28
  @command_options ||= default_options(arg)
30
29
  @command_options[:listing] = arg.is_a?(String) ? arg : arg.inspect
@@ -34,13 +33,13 @@ class Pry
34
33
  end
35
34
 
36
35
  # Define or get the command's description
37
- def description(arg=nil)
36
+ def description(arg = nil)
38
37
  @description = arg if arg
39
38
  @description ||= nil
40
39
  end
41
40
 
42
41
  # Define or get the command's options
43
- def command_options(arg=nil)
42
+ def command_options(arg = nil)
44
43
  @command_options ||= default_options(match)
45
44
  @command_options.merge!(arg) if arg
46
45
  @command_options
@@ -50,7 +49,7 @@ class Pry
50
49
  alias_method :options=, :command_options=
51
50
 
52
51
  # Define or get the command's banner
53
- def banner(arg=nil)
52
+ def banner(arg = nil)
54
53
  @banner = arg if arg
55
54
  @banner ||= description
56
55
  end
@@ -68,10 +67,6 @@ class Pry
68
67
  new.help
69
68
  end
70
69
 
71
- def source_location
72
- block.source_location
73
- end
74
-
75
70
  def source_file
76
71
  Array(block.source_location).first
77
72
  end
@@ -84,27 +79,32 @@ class Pry
84
79
 
85
80
  def default_options(match)
86
81
  {
87
- :requires_gem => [],
88
- :keep_retval => false,
89
- :argument_required => false,
90
- :interpolate => true,
91
- :shellwords => true,
92
- :listing => (String === match ? match : match.inspect),
93
- :use_prefix => true,
94
- :takes_block => false
82
+ requires_gem: [],
83
+ keep_retval: false,
84
+ argument_required: false,
85
+ interpolate: true,
86
+ shellwords: true,
87
+ listing: (String === match ? match : match.inspect),
88
+ use_prefix: true,
89
+ takes_block: false
95
90
  }
96
91
  end
97
92
  end
98
93
 
99
94
  # Make those properties accessible to instances
100
95
  def name; self.class.name; end
96
+
101
97
  def match; self.class.match; end
98
+
102
99
  def description; self.class.description; end
100
+
103
101
  def block; self.class.block; end
102
+
104
103
  def command_options; self.class.options; end
104
+
105
105
  def command_name; self.class.command_name; end
106
+
106
107
  def source; self.class.source; end
107
- def source_location; self.class.source_location; end
108
108
 
109
109
  class << self
110
110
  def name
@@ -169,8 +169,6 @@ class Pry
169
169
 
170
170
  # @deprecated Replaced with {Pry::Hooks#add_hook}. Left for compatibility.
171
171
  # Store hooks to be run before or after the command body.
172
- # @see {Pry::CommandSet#before_command}
173
- # @see {Pry::CommandSet#after_command}
174
172
  def hooks
175
173
  Pry.hooks
176
174
  end
@@ -196,7 +194,7 @@ class Pry
196
194
  # This is usually auto-generated from directory naming, but it can be
197
195
  # manually overridden if necessary.
198
196
  # Group should not be changed once it is initialized.
199
- def group(name=nil)
197
+ def group(name = nil)
200
198
  @group ||= if name
201
199
  name
202
200
  else
@@ -205,9 +203,9 @@ class Pry
205
203
  $1.capitalize.gsub(/_/, " ")
206
204
  when %r{(pry-\w+)-([\d\.]+([\w\.]+)?)}
207
205
  name, version = $1, $2
208
- "#{name.to_s} (v#{version.to_s})"
206
+ "#{name} (v#{version})"
209
207
  when /pryrc/
210
- "~/.pryrc"
208
+ "pryrc"
211
209
  else
212
210
  "(other)"
213
211
  end
@@ -254,6 +252,14 @@ class Pry
254
252
  command_set.to_hash
255
253
  end
256
254
 
255
+ #
256
+ # @deprecated
257
+ # Please use black(), white(), etc directly instead (as you would with helper
258
+ # functions from BaseHelpers and CommandHelpers)
259
+ #
260
+ # @return [Module]
261
+ # Returns Pry::Helpers::Text
262
+ #
257
263
  def text
258
264
  Pry::Helpers::Text
259
265
  end
@@ -264,10 +270,11 @@ class Pry
264
270
 
265
271
  include Pry::Helpers::BaseHelpers
266
272
  include Pry::Helpers::CommandHelpers
273
+ include Pry::Helpers::Text
267
274
 
268
275
  # Instantiate a command, in preparation for calling it.
269
276
  # @param [Hash] context The runtime context to use with this command.
270
- def initialize(context={})
277
+ def initialize(context = {})
271
278
  self.context = context
272
279
  self.target = context[:target]
273
280
  self.output = context[:output]
@@ -338,6 +345,7 @@ class Pry
338
345
 
339
346
  # please call Command.matches? before Command#call_safely
340
347
  raise CommandError, "fatal: called a command which didn't match?!" unless Regexp.last_match
348
+
341
349
  captures = Regexp.last_match.captures
342
350
  pos = Regexp.last_match.end(0)
343
351
 
@@ -450,9 +458,9 @@ class Pry
450
458
 
451
459
  # Generate completions for this command
452
460
  #
453
- # @param [String] search The line typed so far
461
+ # @param [String] _search The line typed so far
454
462
  # @return [Array<String>] Completion words
455
- def complete(search)
463
+ def complete(_search)
456
464
  []
457
465
  end
458
466
 
@@ -537,12 +545,11 @@ class Pry
537
545
  # gems your command needs to run, or to set up state.
538
546
  class ClassCommand < Command
539
547
  class << self
540
-
541
548
  # Ensure that subclasses inherit the options, description and
542
549
  # match from a ClassCommand super class.
543
550
  def inherited(klass)
544
- klass.match match
545
- klass.description description
551
+ klass.match match
552
+ klass.description description
546
553
  klass.command_options options
547
554
  end
548
555
 
@@ -75,7 +75,7 @@ class Pry
75
75
  # # hello john, nice number: 10
76
76
  # # pry(main)> help number
77
77
  # # number-N regex command
78
- def block_command(match, description="No description.", options={}, &block)
78
+ def block_command(match, description = "No description.", options = {}, &block)
79
79
  description, options = ["No description.", description] if description.is_a?(Hash)
80
80
  options = Pry::Command.default_options(match).merge!(options)
81
81
 
@@ -107,7 +107,7 @@ class Pry
107
107
  # end
108
108
  # end
109
109
  #
110
- def create_command(match, description="No description.", options={}, &block)
110
+ def create_command(match, description = "No description.", options = {}, &block)
111
111
  description, options = ["No description.", description] if description.is_a?(Hash)
112
112
  options = Pry::Command.default_options(match).merge!(options)
113
113
 
@@ -116,41 +116,6 @@ class Pry
116
116
  @commands[match]
117
117
  end
118
118
 
119
- # Execute a block of code before a command is invoked. The block also
120
- # gets access to parameters that will be passed to the command and
121
- # is evaluated in the same context.
122
- # @param [String, Regexp] search The match or listing of the command.
123
- # @yield The block to be run before the command.
124
- # @example Display parameter before invoking command
125
- # Pry.config.commands.before_command("whereami") do |n|
126
- # output.puts "parameter passed was #{n}"
127
- # end
128
- # @deprecated Use {Pry::Hooks#add_hook} instead.
129
- def before_command(search, &block)
130
- cmd = find_command_by_match_or_listing(search)
131
- cmd.hooks.add_hook("before_#{cmd.command_name}", random_hook_name, block)
132
- end
133
-
134
- # Execute a block of code after a command is invoked. The block also
135
- # gets access to parameters that will be passed to the command and
136
- # is evaluated in the same context.
137
- # @param [String, Regexp] search The match or listing of the command.
138
- # @yield The block to be run after the command.
139
- # @example Display text 'command complete' after invoking command
140
- # Pry.config.commands.after_command("whereami") do |n|
141
- # output.puts "command complete!"
142
- # end
143
- # @deprecated Use {Pry::Hooks#add_hook} instead.
144
- def after_command(search, &block)
145
- cmd = find_command_by_match_or_listing(search)
146
- cmd.hooks.add_hook("after_#{cmd.command_name}", random_hook_name, block)
147
- end
148
-
149
- def random_hook_name
150
- (0...8).map { ('a'..'z').to_a[rand(26)] }.join
151
- end
152
- private :random_hook_name
153
-
154
119
  def each(&block)
155
120
  @commands.each(&block)
156
121
  end
@@ -209,13 +174,13 @@ class Pry
209
174
  # Pry.config.commands.alias_command "lM", "ls -M"
210
175
  # @example Pass explicit description (overriding default).
211
176
  # Pry.config.commands.alias_command "lM", "ls -M", :desc => "cutiepie"
212
- def alias_command(match, action, options={})
177
+ def alias_command(match, action, options = {})
213
178
  cmd = find_command(action) or fail "Command: `#{action}` not found"
214
179
  original_options = cmd.options.dup
215
180
 
216
181
  options = original_options.merge!({
217
- :desc => "Alias for `#{action}`",
218
- :listing => match
182
+ desc: "Alias for `#{action}`",
183
+ listing: match
219
184
  }).merge!(options)
220
185
 
221
186
  # ensure default description is used if desc is nil
@@ -245,12 +210,12 @@ class Pry
245
210
  # command description to be passed this way too.
246
211
  # @example Renaming the `ls` command and changing its description.
247
212
  # Pry.config.commands.rename "dir", "ls", :description => "DOS friendly ls"
248
- def rename_command(new_match, search, options={})
213
+ def rename_command(new_match, search, options = {})
249
214
  cmd = find_command_by_match_or_listing(search)
250
215
 
251
216
  options = {
252
- :listing => new_match,
253
- :description => cmd.description
217
+ listing: new_match,
218
+ description: cmd.description
254
219
  }.merge!(options)
255
220
 
256
221
  @commands[new_match] = cmd.dup
@@ -260,7 +225,7 @@ class Pry
260
225
  @commands.delete(cmd.match)
261
226
  end
262
227
 
263
- def disabled_command(name_of_disabled_command, message, matcher=name_of_disabled_command)
228
+ def disabled_command(name_of_disabled_command, message, matcher = name_of_disabled_command)
264
229
  create_command name_of_disabled_command do
265
230
  match matcher
266
231
  description ""
@@ -282,7 +247,7 @@ class Pry
282
247
  # end
283
248
  # @example Getting
284
249
  # Pry.config.commands.desc "amend-line"
285
- def desc(search, description=nil)
250
+ def desc(search, description = nil)
286
251
  cmd = find_command_by_match_or_listing(search)
287
252
  return cmd.description if !description
288
253
 
@@ -305,7 +270,6 @@ class Pry
305
270
  helper_module.class_eval(&block)
306
271
  end
307
272
 
308
-
309
273
  # @return [Array]
310
274
  # The list of commands provided by the command set.
311
275
  def list_commands
@@ -352,6 +316,7 @@ class Pry
352
316
  unless Class === command && command < Pry::Command
353
317
  raise TypeError, "command is not a subclass of Pry::Command"
354
318
  end
319
+
355
320
  bind_command_to_pattern = pattern != command.match
356
321
  if bind_command_to_pattern
357
322
  command_copy = command.dup
@@ -394,9 +359,9 @@ class Pry
394
359
  # @param [String] val The line to execute
395
360
  # @param [Hash] context The context to execute the commands with
396
361
  # @return [CommandSet::Result]
397
- def process_line(val, context={})
398
- if command = find_command(val)
399
- context = context.merge(:command_set => self)
362
+ def process_line(val, context = {})
363
+ if (command = find_command(val))
364
+ context = context.merge(command_set: self)
400
365
  retval = command.new(context).process_line(val)
401
366
  Result.new(true, retval)
402
367
  else
@@ -414,13 +379,13 @@ class Pry
414
379
  # @param [String] search The line to search for
415
380
  # @param [Hash] context The context to create the command with
416
381
  # @return [Array<String>]
417
- def complete(search, context={})
418
- if command = find_command(search)
382
+ def complete(search, context = {})
383
+ if (command = find_command(search))
419
384
  command.new(context).complete(search)
420
385
  else
421
386
  @commands.keys.select do |key|
422
387
  String === key && key.start_with?(search)
423
- end.map{ |key| key + " " }
388
+ end.map { |key| key + " " }
424
389
  end
425
390
  end
426
391
  end