irb 1.10.1 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce85a9eb69af7fbbb8cb41a6d34029502d2b6712d916b7a3823176e2769cdcf8
4
- data.tar.gz: 711b52081eb0a97eee4901844b33e8cf9657316c8dde29c9eeb41d3a6998f78e
3
+ metadata.gz: 17969636013c03ffd08d5b53570ec0eda8620855092bd863c5b851e668343007
4
+ data.tar.gz: 7900a886588ebca5839e2b6fac6d538e58febd2706cdbbe979e098f2950d2d79
5
5
  SHA512:
6
- metadata.gz: 300f29f4e769be7ede8371fc7f667fb543eb7d8dd9249b062993074c2bdbb5808a3322cb4bb6a0ff58bd79c2d6e82a3bbac0f78b6a117e0095c63fbfe9431fb8
7
- data.tar.gz: 997b64b19a2902c6a9bc47ee4aff909b133f13e829456cc4fe4cf33b6ca425c8619f58ffda7be71bdd3dde1b91e2d23ba24bad9e9045b612fc190e6ac3fa42e7
6
+ metadata.gz: e9d8fe7568718ce10db38ed1a85ad92473c21ca81738cadaa8a8258adcf18cdbfc5755c61621c336ac4bc53c57a08ad26311a4fc671fb98ad0cd5130c2e7527e
7
+ data.tar.gz: 729f6a0f6ba9fe6cfac3e2ed9e752531006f60c386b3e51fd84c877eeb1b3cdcb0fee1a7bf44c3c0bfa7f0f56def8ad8c7d99413b9b96b304d17e0c15d90aa87
data/.document CHANGED
@@ -1,4 +1,4 @@
1
1
  LICENSE.txt
2
2
  README.md
3
- doc
3
+ doc/irb/indexes.md
4
4
  lib/**/*.rb
data/README.md CHANGED
@@ -15,6 +15,10 @@ The `irb` command from your shell will start the interpreter.
15
15
  - [Debugging with IRB](#debugging-with-irb)
16
16
  - [More about `debug.gem`](#more-about-debuggem)
17
17
  - [Advantages Over `debug.gem`'s Console](#advantages-over-debuggems-console)
18
+ - [Type Based Completion](#type-based-completion)
19
+ - [How to Enable IRB::TypeCompletor](#how-to-enable-irbtypecompletor)
20
+ - [Advantage over Default IRB::RegexpCompletor](#advantage-over-default-irbregexpcompletor)
21
+ - [Difference between Steep's Completion](#difference-between-steeps-completion)
18
22
  - [Configuration](#configuration)
19
23
  - [Environment Variables](#environment-variables)
20
24
  - [Documentation](#documentation)
@@ -105,15 +109,9 @@ Hello World
105
109
 
106
110
  The following commands are available on IRB. You can get the same output from the `show_cmds` command.
107
111
 
108
- ```
109
- Workspace
110
- cwws Show the current workspace.
111
- chws Change the current workspace to an object.
112
- workspaces Show workspaces.
113
- pushws Push an object to the workspace stack.
114
- popws Pop a workspace from the workspace stack.
115
-
112
+ ```txt
116
113
  IRB
114
+ exit Exit the current irb session.
117
115
  irb_load Load a Ruby file.
118
116
  irb_require Require a Ruby file.
119
117
  source Loads a given file in the current session.
@@ -121,6 +119,13 @@ IRB
121
119
  show_cmds List all available commands and their description.
122
120
  history Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output.
123
121
 
122
+ Workspace
123
+ cwws Show the current workspace.
124
+ chws Change the current workspace to an object.
125
+ workspaces Show workspaces.
126
+ pushws Push an object to the workspace stack.
127
+ popws Pop a workspace from the workspace stack.
128
+
124
129
  Multi-irb (DEPRECATED)
125
130
  irb Start a child IRB.
126
131
  jobs List of current sessions.
@@ -149,6 +154,10 @@ Context
149
154
  ls Show methods, constants, and variables. `-g [query]` or `-G [query]` allows you to filter out the output.
150
155
  show_source Show the source code of a given method or constant.
151
156
  whereami Show the source code around binding.irb again.
157
+
158
+ Aliases
159
+ $ Alias for `show_source`
160
+ @ Alias for `whereami`
152
161
  ```
153
162
 
154
163
  ## Debugging with IRB
@@ -242,15 +251,33 @@ IRB's default completion `IRB::RegexpCompletor` uses Regexp. IRB has another exp
242
251
 
243
252
  ### How to Enable IRB::TypeCompletor
244
253
 
245
- To enable IRB::TypeCompletor, run IRB with `--type-completor` option
254
+ Install [ruby/repl_type_completor](https://github.com/ruby/repl_type_completor/) with:
255
+ ```
256
+ $ gem install repl_type_completor
257
+ ```
258
+ Or add these lines to your project's Gemfile.
259
+ ```ruby
260
+ gem 'irb'
261
+ gem 'repl_type_completor', group: [:development, :test]
262
+ ```
263
+
264
+ Now you can use type based completion by:
265
+
266
+ Running IRB with the `--type-completor` option
246
267
  ```
247
268
  $ irb --type-completor
248
269
  ```
249
- Or write the code below to IRB's rc-file.
270
+
271
+ Or writing this line to IRB's rc-file (e.g. `~/.irbrc`)
250
272
  ```ruby
251
273
  IRB.conf[:COMPLETOR] = :type # default is :regexp
252
274
  ```
253
- You also need `gem repl_type_completor` to use this feature.
275
+
276
+ Or setting the environment variable `IRB_COMPLETOR`
277
+ ```ruby
278
+ ENV['IRB_COMPLETOR'] = 'type'
279
+ IRB.start
280
+ ```
254
281
 
255
282
  To check if it's enabled, type `irb_info` into IRB and see the `Completion` section.
256
283
  ```
data/irb.gemspec CHANGED
@@ -41,6 +41,6 @@ Gem::Specification.new do |spec|
41
41
 
42
42
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7")
43
43
 
44
- spec.add_dependency "reline", ">= 0.3.8"
44
+ spec.add_dependency "reline", ">= 0.4.2"
45
45
  spec.add_dependency "rdoc"
46
46
  end
data/lib/irb/cmd/debug.rb CHANGED
@@ -31,7 +31,7 @@ module IRB
31
31
  # 4. Exit the current Irb#run call via `throw :IRB_EXIT`.
32
32
  # 5. `Irb#debug_break` will be called and trigger the breakpoint, which will run the intended command.
33
33
  unless binding_irb?
34
- puts "`debug` command is only available when IRB is started with binding.irb"
34
+ puts "Debugging commands are only available when IRB is started with binding.irb"
35
35
  return
36
36
  end
37
37
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "nop"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module ExtendCommand
9
+ class Exit < Nop
10
+ category "IRB"
11
+ description "Exit the current irb session."
12
+
13
+ def execute(*)
14
+ IRB.irb_exit
15
+ rescue UncaughtThrowError
16
+ Kernel.exit
17
+ end
18
+ end
19
+ end
20
+
21
+ # :startdoc:
22
+ end
@@ -12,32 +12,29 @@ module IRB
12
12
  super(*args)
13
13
  end
14
14
 
15
- def execute(type = nil, arg = nil, &block)
15
+ def execute(type = nil, arg = nil)
16
16
  # Please check IRB.init_config in lib/irb/init.rb that sets
17
17
  # IRB.conf[:MEASURE_PROC] to register default "measure" methods,
18
18
  # "measure :time" (abbreviated as "measure") and "measure :stackprof".
19
+
20
+ if block_given?
21
+ warn 'Configure IRB.conf[:MEASURE_PROC] to add custom measure methods.'
22
+ return
23
+ end
24
+
19
25
  case type
20
26
  when :off
21
- IRB.conf[:MEASURE] = nil
22
27
  IRB.unset_measure_callback(arg)
23
28
  when :list
24
29
  IRB.conf[:MEASURE_CALLBACKS].each do |type_name, _, arg_val|
25
30
  puts "- #{type_name}" + (arg_val ? "(#{arg_val.inspect})" : '')
26
31
  end
27
32
  when :on
28
- IRB.conf[:MEASURE] = true
29
- added = IRB.set_measure_callback(type, arg)
33
+ added = IRB.set_measure_callback(arg)
30
34
  puts "#{added[0]} is added." if added
31
35
  else
32
- if block_given?
33
- IRB.conf[:MEASURE] = true
34
- added = IRB.set_measure_callback(&block)
35
- puts "#{added[0]} is added." if added
36
- else
37
- IRB.conf[:MEASURE] = true
38
- added = IRB.set_measure_callback(type, arg)
39
- puts "#{added[0]} is added." if added
40
- end
36
+ added = IRB.set_measure_callback(type, arg)
37
+ puts "#{added[0]} is added." if added
41
38
  end
42
39
  nil
43
40
  end
@@ -27,17 +27,14 @@ module IRB
27
27
  puts "Error: Expected a string but got #{str.inspect}"
28
28
  return
29
29
  end
30
- if str.include? " -s"
31
- str, esses = str.split(" -")
32
- s_count = esses.count("^s").zero? ? esses.size : 1
33
- source = SourceFinder.new(@irb_context).find_source(str, s_count)
34
- else
35
- source = SourceFinder.new(@irb_context).find_source(str)
36
- end
30
+
31
+ str, esses = str.split(" -")
32
+ super_level = esses ? esses.count("s") : 0
33
+ source = SourceFinder.new(@irb_context).find_source(str, super_level)
37
34
 
38
35
  if source
39
36
  show_source(source)
40
- elsif s_count
37
+ elsif super_level > 0
41
38
  puts "Error: Couldn't locate a super definition for #{str}"
42
39
  else
43
40
  puts "Error: Couldn't locate a definition for #{str}"
@@ -406,7 +406,13 @@ module IRB
406
406
  else
407
407
  select_message(receiver, message, candidates.sort)
408
408
  end
409
-
409
+ when /^\s*$/
410
+ # empty input
411
+ if doc_namespace
412
+ nil
413
+ else
414
+ []
415
+ end
410
416
  else
411
417
  if doc_namespace
412
418
  vars = (bind.local_variables | bind.eval_instance_variables).collect{|m| m.to_s}
data/lib/irb/context.rb CHANGED
@@ -264,15 +264,15 @@ module IRB
264
264
  attr_reader :prompt_mode
265
265
  # Standard IRB prompt.
266
266
  #
267
- # See IRB@Customizing+the+IRB+Prompt for more information.
267
+ # See {Custom Prompts}[rdoc-ref:IRB@Custom+Prompts] for more information.
268
268
  attr_accessor :prompt_i
269
269
  # IRB prompt for continuated strings.
270
270
  #
271
- # See IRB@Customizing+the+IRB+Prompt for more information.
271
+ # See {Custom Prompts}[rdoc-ref:IRB@Custom+Prompts] for more information.
272
272
  attr_accessor :prompt_s
273
273
  # IRB prompt for continuated statement. (e.g. immediately after an +if+)
274
274
  #
275
- # See IRB@Customizing+the+IRB+Prompt for more information.
275
+ # See {Custom Prompts}[rdoc-ref:IRB@Custom+Prompts] for more information.
276
276
  attr_accessor :prompt_c
277
277
 
278
278
  # TODO: Remove this when developing v2.0
@@ -394,8 +394,6 @@ module IRB
394
394
  # The default value is 16.
395
395
  #
396
396
  # Can also be set using the +--back-trace-limit+ command line option.
397
- #
398
- # See IRB@Command+line+options for more command line options.
399
397
  attr_accessor :back_trace_limit
400
398
 
401
399
  # User-defined IRB command aliases
@@ -463,7 +461,7 @@ module IRB
463
461
 
464
462
  # Sets the +mode+ of the prompt in this context.
465
463
  #
466
- # See IRB@Customizing+the+IRB+Prompt for more information.
464
+ # See {Custom Prompts}[rdoc-ref:IRB@Custom+Prompts] for more information.
467
465
  def prompt_mode=(mode)
468
466
  @prompt_mode = mode
469
467
  pconf = IRB.conf[:PROMPT][mode]
@@ -501,8 +499,6 @@ module IRB
501
499
  #
502
500
  # Can also be set using the +--inspect+ and +--noinspect+ command line
503
501
  # options.
504
- #
505
- # See IRB@Command+line+options for more command line options.
506
502
  def inspect_mode=(opt)
507
503
 
508
504
  if i = Inspector::INSPECTORS[opt]
@@ -577,14 +573,6 @@ module IRB
577
573
  @inspect_method.inspect_value(@last_value)
578
574
  end
579
575
 
580
- alias __exit__ exit
581
- # Exits the current session, see IRB.irb_exit
582
- def exit(ret = 0)
583
- IRB.irb_exit(@irb, ret)
584
- rescue UncaughtThrowError
585
- super
586
- end
587
-
588
576
  NOPRINTING_IVARS = ["@last_value"] # :nodoc:
589
577
  NO_INSPECTING_IVARS = ["@irb", "@io"] # :nodoc:
590
578
  IDNAME_IVARS = ["@prompt_mode"] # :nodoc:
@@ -16,15 +16,6 @@ module IRB # :nodoc:
16
16
  # See #install_alias_method.
17
17
  OVERRIDE_ALL = 0x02
18
18
 
19
- # Quits the current irb context
20
- #
21
- # +ret+ is the optional signal or message to send to Context#exit
22
- #
23
- # Same as <code>IRB.CurrentContext.exit</code>.
24
- def irb_exit(ret = 0)
25
- irb_context.exit(ret)
26
- end
27
-
28
19
  # Displays current configuration.
29
20
  #
30
21
  # Modifying the configuration is achieved by sending a message to IRB.conf.
@@ -35,13 +26,16 @@ module IRB # :nodoc:
35
26
  @ALIASES = [
36
27
  [:context, :irb_context, NO_OVERRIDE],
37
28
  [:conf, :irb_context, NO_OVERRIDE],
38
- [:irb_quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
39
- [:exit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
40
- [:quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
41
29
  ]
42
30
 
43
31
 
44
32
  @EXTEND_COMMANDS = [
33
+ [
34
+ :irb_exit, :Exit, "cmd/exit",
35
+ [:exit, OVERRIDE_PRIVATE_ONLY],
36
+ [:quit, OVERRIDE_PRIVATE_ONLY],
37
+ [:irb_quit, OVERRIDE_PRIVATE_ONLY],
38
+ ],
45
39
  [
46
40
  :irb_current_working_workspace, :CurrentWorkingWorkspace, "cmd/chws",
47
41
  [:cwws, NO_OVERRIDE],
data/lib/irb/help.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module IRB
8
- # Outputs the irb help message, see IRB@Command+line+options.
8
+ # Outputs the irb help message, see IRB@Command-Line+Options.
9
9
  def IRB.print_usage
10
10
  lc = IRB.conf[:LC_MESSAGES]
11
11
  path = lc.find("irb/help-message")
data/lib/irb/init.rb CHANGED
@@ -215,6 +215,7 @@ module IRB # :nodoc:
215
215
  added = [:TIME, IRB.conf[:MEASURE_PROC][:TIME], arg]
216
216
  end
217
217
  if added
218
+ IRB.conf[:MEASURE] = true
218
219
  found = IRB.conf[:MEASURE_CALLBACKS].find{ |m| m[0] == added[0] && m[2] == added[2] }
219
220
  if found
220
221
  # already added
@@ -235,6 +236,7 @@ module IRB # :nodoc:
235
236
  type_sym = type.upcase.to_sym
236
237
  IRB.conf[:MEASURE_CALLBACKS].reject!{ |t, | t == type_sym }
237
238
  end
239
+ IRB.conf[:MEASURE] = nil if IRB.conf[:MEASURE_CALLBACKS].empty?
238
240
  end
239
241
 
240
242
  def IRB.init_error
@@ -387,18 +389,16 @@ module IRB # :nodoc:
387
389
  $LOAD_PATH.unshift(*load_path)
388
390
  end
389
391
 
390
- # running config
392
+ # Run the config file
391
393
  def IRB.run_config
392
394
  if @CONF[:RC]
393
395
  begin
394
- load rc_file
395
- rescue LoadError, Errno::ENOENT
396
- rescue # StandardError, ScriptError
397
- print "load error: #{rc_file}\n"
398
- print $!.class, ": ", $!, "\n"
399
- for err in $@[0, $@.size - 2]
400
- print "\t", err, "\n"
401
- end
396
+ file = rc_file
397
+ # Because rc_file always returns `HOME/.irbrc` even if no rc file is present, we can't warn users about missing rc files.
398
+ # Otherwise, it'd be very noisy.
399
+ load file if File.exist?(file)
400
+ rescue StandardError, ScriptError => e
401
+ warn "Error loading RC file '#{file}':\n#{e.full_message(highlight: false)}"
402
402
  end
403
403
  end
404
404
  end
@@ -416,7 +416,7 @@ module IRB # :nodoc:
416
416
  end
417
417
  case rc_file = @CONF[:RC_NAME_GENERATOR].call(ext)
418
418
  when String
419
- return rc_file
419
+ rc_file
420
420
  else
421
421
  fail IllegalRCNameGenerator
422
422
  end
@@ -291,11 +291,13 @@ module IRB
291
291
  @auto_indent_proc = block
292
292
  end
293
293
 
294
+ def retrieve_doc_namespace(matched)
295
+ preposing, _target, postposing, bind = @completion_params
296
+ @completor.doc_namespace(preposing, matched, postposing, bind: bind)
297
+ end
298
+
294
299
  def show_doc_dialog_proc
295
- doc_namespace = ->(matched) {
296
- preposing, _target, postposing, bind = @completion_params
297
- @completor.doc_namespace(preposing, matched, postposing, bind: bind)
298
- }
300
+ input_method = self # self is changed in the lambda below.
299
301
  ->() {
300
302
  dialog.trap_key = nil
301
303
  alt_d = [
@@ -311,7 +313,7 @@ module IRB
311
313
  cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
312
314
  return nil if result.nil? or pointer.nil? or pointer < 0
313
315
 
314
- name = doc_namespace.call(result[pointer])
316
+ name = input_method.retrieve_doc_namespace(result[pointer])
315
317
  # Use first one because document dialog does not support multiple namespaces.
316
318
  name = name.first if name.is_a?(Array)
317
319
 
@@ -419,8 +421,7 @@ module IRB
419
421
  return
420
422
  end
421
423
 
422
- _target, preposing, postposing, bind = @completion_params
423
- namespace = @completor.doc_namespace(preposing, matched, postposing, bind: bind)
424
+ namespace = retrieve_doc_namespace(matched)
424
425
  return unless namespace
425
426
 
426
427
  driver ||= RDoc::RI::Driver.new
@@ -16,10 +16,10 @@ module IRB
16
16
  @irb_context = irb_context
17
17
  end
18
18
 
19
- def find_source(signature, s_count = nil)
19
+ def find_source(signature, super_level = 0)
20
20
  context_binding = @irb_context.workspace.binding
21
21
  case signature
22
- when /\A[A-Z]\w*(::[A-Z]\w*)*\z/ # Const::Name
22
+ when /\A(::)?[A-Z]\w*(::[A-Z]\w*)*\z/ # Const::Name
23
23
  eval(signature, context_binding) # trigger autoload
24
24
  base = context_binding.receiver.yield_self { |r| r.is_a?(Module) ? r : Object }
25
25
  file, line = base.const_source_location(signature)
@@ -27,14 +27,15 @@ module IRB
27
27
  owner = eval(Regexp.last_match[:owner], context_binding)
28
28
  method = Regexp.last_match[:method]
29
29
  return unless owner.respond_to?(:instance_method)
30
- file, line = method_target(owner, s_count, method, "owner")
30
+ file, line = method_target(owner, super_level, method, "owner")
31
31
  when /\A((?<receiver>.+)(\.|::))?(?<method>[^ :.]+)\z/ # method, receiver.method, receiver::method
32
32
  receiver = eval(Regexp.last_match[:receiver] || 'self', context_binding)
33
33
  method = Regexp.last_match[:method]
34
34
  return unless receiver.respond_to?(method, true)
35
- file, line = method_target(receiver, s_count, method, "receiver")
35
+ file, line = method_target(receiver, super_level, method, "receiver")
36
36
  end
37
- if file && line && File.exist?(file)
37
+ # If the line is zero, it means that the target's source is probably in a binary file, which we should ignore.
38
+ if file && line && !line.zero? && File.exist?(file)
38
39
  Source.new(file: file, first_line: line, last_line: find_end(file, line))
39
40
  end
40
41
  end
@@ -60,20 +61,14 @@ module IRB
60
61
  first_line
61
62
  end
62
63
 
63
- def method_target(owner_receiver, s_count, method, type)
64
+ def method_target(owner_receiver, super_level, method, type)
64
65
  case type
65
66
  when "owner"
66
67
  target_method = owner_receiver.instance_method(method)
67
- return target_method.source_location unless s_count
68
68
  when "receiver"
69
- if s_count
70
- target_method = owner_receiver.class.instance_method(method)
71
- else
72
- target_method = method
73
- return owner_receiver.method(method).source_location
74
- end
69
+ target_method = owner_receiver.method(method)
75
70
  end
76
- s_count.times do |s|
71
+ super_level.times do |s|
77
72
  target_method = target_method.super_method if target_method
78
73
  end
79
74
  target_method.nil? ? nil : target_method.source_location
data/lib/irb/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module IRB # :nodoc:
8
- VERSION = "1.10.1"
8
+ VERSION = "1.11.1"
9
9
  @RELEASE_VERSION = VERSION
10
- @LAST_UPDATE_DATE = "2023-12-05"
10
+ @LAST_UPDATE_DATE = "2024-01-08"
11
11
  end
data/lib/irb/xmp.rb CHANGED
@@ -44,8 +44,8 @@ class XMP
44
44
  # The top-level binding or, optional +bind+ parameter will be used when
45
45
  # creating the workspace. See WorkSpace.new for more information.
46
46
  #
47
- # This uses the +:XMP+ prompt mode, see IRB@Customizing+the+IRB+Prompt for
48
- # full detail.
47
+ # This uses the +:XMP+ prompt mode.
48
+ # See {Custom Prompts}[rdoc-ref:IRB@Custom+Prompts] for more information.
49
49
  def initialize(bind = nil)
50
50
  IRB.init_config(nil)
51
51