irb 1.6.3 → 1.6.4
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 +4 -4
- data/README.md +3 -0
- data/irb.gemspec +1 -1
- data/lib/irb/cmd/nop.rb +5 -14
- data/lib/irb/cmd/show_source.rb +1 -1
- data/lib/irb/color.rb +3 -9
- data/lib/irb/color_printer.rb +6 -1
- data/lib/irb/completion.rb +1 -34
- data/lib/irb/ext/loader.rb +1 -24
- data/lib/irb/ext/tracer.rb +0 -1
- data/lib/irb/extend-command.rb +7 -83
- data/lib/irb/inspector.rb +1 -2
- data/lib/irb/ruby-lex.rb +8 -12
- data/lib/irb/version.rb +2 -2
- data/lib/irb.rb +0 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db51125adbe98b16228e314bff627b1cec953b92f32c774c4b9a820dc3bfc40b
|
4
|
+
data.tar.gz: ead3ebf30f5a4369d8cc2767691397d766bab8532031f8f505c2d0b3f251e071
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2f749ce66ed43433fbbc7ec8682a0c3f0180ac8fb676739e5c3cbf0eb2f8bbb89a7896af11120bdeedd730e57edddaeabf932ae22ac55ad33c99f8408ffc832
|
7
|
+
data.tar.gz: 55621e3a5f9926c3f1b44426c23b9b08543920075fa0d32eeda8b7db35ded09aba6c311011e7f8397a6a5089bbb63d2b2e2603c1d7e254b77a16b93ca35b76f3
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# IRB
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/irb)
|
4
|
+
[](https://github.com/ruby/irb/actions/workflows/test.yml)
|
5
|
+
|
3
6
|
IRB stands for "interactive Ruby" and is a tool to interactively execute Ruby expressions read from the standard input.
|
4
7
|
|
5
8
|
The `irb` command from your shell will start the interpreter.
|
data/irb.gemspec
CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
40
40
|
spec.require_paths = ["lib"]
|
41
41
|
|
42
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
42
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7")
|
43
43
|
|
44
44
|
spec.add_dependency "reline", ">= 0.3.0"
|
45
45
|
end
|
data/lib/irb/cmd/nop.rb
CHANGED
@@ -30,20 +30,11 @@ module IRB
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
puts e.message
|
39
|
-
end
|
40
|
-
else
|
41
|
-
def self.execute(conf, *opts, &block)
|
42
|
-
command = new(conf)
|
43
|
-
command.execute(*opts, &block)
|
44
|
-
rescue CommandArgumentError => e
|
45
|
-
puts e.message
|
46
|
-
end
|
33
|
+
def self.execute(conf, *opts, **kwargs, &block)
|
34
|
+
command = new(conf)
|
35
|
+
command.execute(*opts, **kwargs, &block)
|
36
|
+
rescue CommandArgumentError => e
|
37
|
+
puts e.message
|
47
38
|
end
|
48
39
|
|
49
40
|
def initialize(conf)
|
data/lib/irb/cmd/show_source.rb
CHANGED
@@ -27,7 +27,7 @@ module IRB
|
|
27
27
|
when /\A[A-Z]\w*(::[A-Z]\w*)*\z/ # Const::Name
|
28
28
|
eval(str, irb_context.workspace.binding) # trigger autoload
|
29
29
|
base = irb_context.workspace.binding.receiver.yield_self { |r| r.is_a?(Module) ? r : Object }
|
30
|
-
file, line = base.const_source_location(str)
|
30
|
+
file, line = base.const_source_location(str)
|
31
31
|
when /\A(?<owner>[A-Z]\w*(::[A-Z]\w*)*)#(?<method>[^ :.]+)\z/ # Class#method
|
32
32
|
owner = eval(Regexp.last_match[:owner], irb_context.workspace.binding)
|
33
33
|
method = Regexp.last_match[:method]
|
data/lib/irb/color.rb
CHANGED
@@ -197,15 +197,9 @@ module IRB # :nodoc:
|
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
on_scan.call(elem)
|
204
|
-
end
|
205
|
-
else
|
206
|
-
lexer.parse.sort_by(&:pos).each do |elem|
|
207
|
-
on_scan.call(elem)
|
208
|
-
end
|
200
|
+
lexer.scan.each do |elem|
|
201
|
+
next if allow_last_error and /meets end of file|unexpected end-of-input/ =~ elem.message
|
202
|
+
on_scan.call(elem)
|
209
203
|
end
|
210
204
|
# yield uncolorable DATA section
|
211
205
|
yield(nil, inner_code.byteslice(byte_pos...inner_code.bytesize), nil) if byte_pos < inner_code.bytesize
|
data/lib/irb/color_printer.rb
CHANGED
@@ -4,6 +4,9 @@ require_relative 'color'
|
|
4
4
|
|
5
5
|
module IRB
|
6
6
|
class ColorPrinter < ::PP
|
7
|
+
METHOD_RESPOND_TO = Object.instance_method(:respond_to?)
|
8
|
+
METHOD_INSPECT = Object.instance_method(:inspect)
|
9
|
+
|
7
10
|
class << self
|
8
11
|
def pp(obj, out = $>, width = screen_width)
|
9
12
|
q = ColorPrinter.new(out, width)
|
@@ -22,9 +25,11 @@ module IRB
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def pp(obj)
|
25
|
-
if obj
|
28
|
+
if String === obj
|
26
29
|
# Avoid calling Ruby 2.4+ String#pretty_print that splits a string by "\n"
|
27
30
|
text(obj.inspect)
|
31
|
+
elsif !METHOD_RESPOND_TO.bind(obj).call(:inspect)
|
32
|
+
text(METHOD_INSPECT.bind(obj).call)
|
28
33
|
else
|
29
34
|
super
|
30
35
|
end
|
data/lib/irb/completion.rb
CHANGED
@@ -58,19 +58,11 @@ module IRB
|
|
58
58
|
|
59
59
|
BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
|
60
60
|
|
61
|
-
def self.absolute_path?(p) # TODO Remove this method after 2.6 EOL.
|
62
|
-
if File.respond_to?(:absolute_path?)
|
63
|
-
File.absolute_path?(p)
|
64
|
-
else
|
65
|
-
File.absolute_path(p) == p
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
61
|
GEM_PATHS =
|
70
62
|
if defined?(Gem::Specification)
|
71
63
|
Gem::Specification.latest_specs(true).map { |s|
|
72
64
|
s.require_paths.map { |p|
|
73
|
-
if absolute_path?(p)
|
65
|
+
if File.absolute_path?(p)
|
74
66
|
p
|
75
67
|
else
|
76
68
|
File.join(s.full_gem_path, p)
|
@@ -450,30 +442,5 @@ module IRB
|
|
450
442
|
end
|
451
443
|
end
|
452
444
|
end
|
453
|
-
|
454
|
-
def self.ignored_modules
|
455
|
-
# We could cache the result, but this is very fast already.
|
456
|
-
# By using this approach, we avoid Module#name calls, which are
|
457
|
-
# relatively slow when there are a lot of anonymous modules defined.
|
458
|
-
s = {}
|
459
|
-
|
460
|
-
scanner = lambda do |m|
|
461
|
-
next if s.include?(m) # IRB::ExtendCommandBundle::EXCB recurses.
|
462
|
-
s[m] = true
|
463
|
-
m.constants(false).each do |c|
|
464
|
-
value = m.const_get(c)
|
465
|
-
scanner.call(value) if value.is_a?(Module)
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
|
-
%i(IRB RubyLex).each do |sym|
|
470
|
-
next unless Object.const_defined?(sym)
|
471
|
-
scanner.call(Object.const_get(sym))
|
472
|
-
end
|
473
|
-
|
474
|
-
s.delete(IRB::Context) if defined?(IRB::Context)
|
475
|
-
|
476
|
-
s
|
477
|
-
end
|
478
445
|
end
|
479
446
|
end
|
data/lib/irb/ext/loader.rb
CHANGED
@@ -24,31 +24,8 @@ module IRB # :nodoc:
|
|
24
24
|
load_file(path, priv)
|
25
25
|
end
|
26
26
|
|
27
|
-
if File.respond_to?(:absolute_path?)
|
28
|
-
def absolute_path?(path)
|
29
|
-
File.absolute_path?(path)
|
30
|
-
end
|
31
|
-
else
|
32
|
-
separator =
|
33
|
-
if File::ALT_SEPARATOR
|
34
|
-
"[#{Regexp.quote(File::SEPARATOR + File::ALT_SEPARATOR)}]"
|
35
|
-
else
|
36
|
-
File::SEPARATOR
|
37
|
-
end
|
38
|
-
ABSOLUTE_PATH_PATTERN = # :nodoc:
|
39
|
-
case Dir.pwd
|
40
|
-
when /\A\w:/, /\A#{separator}{2}/
|
41
|
-
/\A(?:\w:|#{separator})#{separator}/
|
42
|
-
else
|
43
|
-
/\A#{separator}/
|
44
|
-
end
|
45
|
-
def absolute_path?(path)
|
46
|
-
ABSOLUTE_PATH_PATTERN =~ path
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
27
|
def search_file_from_ruby_path(fn) # :nodoc:
|
51
|
-
if absolute_path?(fn)
|
28
|
+
if File.absolute_path?(fn)
|
52
29
|
return fn if File.exist?(fn)
|
53
30
|
return nil
|
54
31
|
end
|
data/lib/irb/ext/tracer.rb
CHANGED
data/lib/irb/extend-command.rb
CHANGED
@@ -246,7 +246,7 @@ module IRB # :nodoc:
|
|
246
246
|
#
|
247
247
|
# The optional +load_file+ parameter will be required within the method
|
248
248
|
# definition.
|
249
|
-
def self.def_extend_command(cmd_name, cmd_class, load_file
|
249
|
+
def self.def_extend_command(cmd_name, cmd_class, load_file, *aliases)
|
250
250
|
case cmd_class
|
251
251
|
when Symbol
|
252
252
|
cmd_class = cmd_class.id2name
|
@@ -255,34 +255,12 @@ module IRB # :nodoc:
|
|
255
255
|
cmd_class = cmd_class.name
|
256
256
|
end
|
257
257
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s }
|
265
|
-
args << "*opts#{kwargs}" if arity < 0
|
266
|
-
args << "&block"
|
267
|
-
args = args.join(", ")
|
268
|
-
line = __LINE__; eval %[
|
269
|
-
unless singleton_class.class_variable_defined?(:@@#{cmd_name}_)
|
270
|
-
singleton_class.class_variable_set(:@@#{cmd_name}_, true)
|
271
|
-
def self.#{cmd_name}_(\#{args})
|
272
|
-
::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
|
273
|
-
end
|
274
|
-
end
|
275
|
-
], nil, __FILE__, line
|
276
|
-
__send__ :#{cmd_name}_, *opts#{kwargs}, &b
|
277
|
-
end
|
278
|
-
], nil, __FILE__, line
|
279
|
-
else
|
280
|
-
line = __LINE__; eval %[
|
281
|
-
def #{cmd_name}(*opts, &b)
|
282
|
-
::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
|
283
|
-
end
|
284
|
-
], nil, __FILE__, line
|
285
|
-
end
|
258
|
+
line = __LINE__; eval %[
|
259
|
+
def #{cmd_name}(*opts, **kwargs, &b)
|
260
|
+
Kernel.require_relative "#{load_file}"
|
261
|
+
::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, *opts, **kwargs, &b)
|
262
|
+
end
|
263
|
+
], nil, __FILE__, line
|
286
264
|
|
287
265
|
for ali, flag in aliases
|
288
266
|
@ALIASES.push [ali, cmd_name, flag]
|
@@ -371,58 +349,4 @@ module IRB # :nodoc:
|
|
371
349
|
|
372
350
|
CE.install_extend_commands
|
373
351
|
end
|
374
|
-
|
375
|
-
# A convenience module for extending Ruby methods.
|
376
|
-
module MethodExtender
|
377
|
-
# Extends the given +base_method+ with a prefix call to the given
|
378
|
-
# +extend_method+.
|
379
|
-
def def_pre_proc(base_method, extend_method)
|
380
|
-
base_method = base_method.to_s
|
381
|
-
extend_method = extend_method.to_s
|
382
|
-
|
383
|
-
alias_name = new_alias_name(base_method)
|
384
|
-
module_eval %[
|
385
|
-
alias_method alias_name, base_method
|
386
|
-
def #{base_method}(*opts)
|
387
|
-
__send__ :#{extend_method}, *opts
|
388
|
-
__send__ :#{alias_name}, *opts
|
389
|
-
end
|
390
|
-
]
|
391
|
-
end
|
392
|
-
|
393
|
-
# Extends the given +base_method+ with a postfix call to the given
|
394
|
-
# +extend_method+.
|
395
|
-
def def_post_proc(base_method, extend_method)
|
396
|
-
base_method = base_method.to_s
|
397
|
-
extend_method = extend_method.to_s
|
398
|
-
|
399
|
-
alias_name = new_alias_name(base_method)
|
400
|
-
module_eval %[
|
401
|
-
alias_method alias_name, base_method
|
402
|
-
def #{base_method}(*opts)
|
403
|
-
__send__ :#{alias_name}, *opts
|
404
|
-
__send__ :#{extend_method}, *opts
|
405
|
-
end
|
406
|
-
]
|
407
|
-
end
|
408
|
-
|
409
|
-
# Returns a unique method name to use as an alias for the given +name+.
|
410
|
-
#
|
411
|
-
# Usually returns <code>#{prefix}#{name}#{postfix}<num></code>, example:
|
412
|
-
#
|
413
|
-
# new_alias_name('foo') #=> __alias_of__foo__
|
414
|
-
# def bar; end
|
415
|
-
# new_alias_name('bar') #=> __alias_of__bar__2
|
416
|
-
def new_alias_name(name, prefix = "__alias_of__", postfix = "__")
|
417
|
-
base_name = "#{prefix}#{name}#{postfix}"
|
418
|
-
all_methods = instance_methods(true) + private_instance_methods(true)
|
419
|
-
same_methods = all_methods.grep(/^#{Regexp.quote(base_name)}[0-9]*$/)
|
420
|
-
return base_name if same_methods.empty?
|
421
|
-
no = same_methods.size
|
422
|
-
while !same_methods.include?(alias_name = base_name + no)
|
423
|
-
no += 1
|
424
|
-
end
|
425
|
-
alias_name
|
426
|
-
end
|
427
|
-
end
|
428
352
|
end
|
data/lib/irb/inspector.rb
CHANGED
@@ -98,8 +98,7 @@ module IRB # :nodoc:
|
|
98
98
|
puts "An error occurred when inspecting the object: #{e.inspect}"
|
99
99
|
|
100
100
|
begin
|
101
|
-
|
102
|
-
puts "Result of Kernel#inspect: #{KERNEL_INSPECT.bind(v).call}"
|
101
|
+
puts "Result of Kernel#inspect: #{KERNEL_INSPECT.bind_call(v)}"
|
103
102
|
''
|
104
103
|
rescue => e
|
105
104
|
puts "An error occurred when running Kernel#inspect: #{e.inspect}"
|
data/lib/irb/ruby-lex.rb
CHANGED
@@ -148,19 +148,15 @@ class RubyLex
|
|
148
148
|
|
149
149
|
compile_with_errors_suppressed(code, line_no: line_no) do |inner_code, line_no|
|
150
150
|
lexer = Ripper::Lexer.new(inner_code, '-', line_no)
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
if
|
157
|
-
|
158
|
-
|
159
|
-
tokens << t
|
160
|
-
end
|
151
|
+
lexer.scan.each_with_object([]) do |t, tokens|
|
152
|
+
next if t.pos.first == 0
|
153
|
+
prev_tk = tokens.last
|
154
|
+
position_overlapped = prev_tk && t.pos[0] == prev_tk.pos[0] && t.pos[1] < prev_tk.pos[1] + prev_tk.tok.bytesize
|
155
|
+
if position_overlapped
|
156
|
+
tokens[-1] = t if ERROR_TOKENS.include?(prev_tk.event) && !ERROR_TOKENS.include?(t.event)
|
157
|
+
else
|
158
|
+
tokens << t
|
161
159
|
end
|
162
|
-
else
|
163
|
-
lexer.parse.reject { |it| it.pos.first == 0 }.sort_by(&:pos)
|
164
160
|
end
|
165
161
|
end
|
166
162
|
ensure
|
data/lib/irb/version.rb
CHANGED
data/lib/irb.rb
CHANGED
@@ -416,11 +416,6 @@ module IRB
|
|
416
416
|
irb.run(@CONF)
|
417
417
|
end
|
418
418
|
|
419
|
-
# Calls each event hook of <code>IRB.conf[:AT_EXIT]</code> when the current session quits.
|
420
|
-
def IRB.irb_at_exit
|
421
|
-
@CONF[:AT_EXIT].each{|hook| hook.call}
|
422
|
-
end
|
423
|
-
|
424
419
|
# Quits irb
|
425
420
|
def IRB.irb_exit(irb, ret)
|
426
421
|
throw :IRB_EXIT, ret
|
@@ -565,7 +560,6 @@ module IRB
|
|
565
560
|
@scanner.each_top_level_statement do |line, line_no|
|
566
561
|
signal_status(:IN_EVAL) do
|
567
562
|
begin
|
568
|
-
line.untaint if RUBY_VERSION < '2.7'
|
569
563
|
if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty?
|
570
564
|
IRB.set_measure_callback
|
571
565
|
end
|
@@ -897,11 +891,6 @@ module IRB
|
|
897
891
|
ensure
|
898
892
|
$VERBOSE = verbose
|
899
893
|
end
|
900
|
-
|
901
|
-
ATTR_TTY = "\e[%sm"
|
902
|
-
def ATTR_TTY.[](*a) self % a.join(";"); end
|
903
|
-
ATTR_PLAIN = ""
|
904
|
-
def ATTR_PLAIN.[](*) self; end
|
905
894
|
end
|
906
895
|
|
907
896
|
def @CONF.inspect
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aycabta
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: reline
|
@@ -123,14 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
requirements:
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version: '2.
|
126
|
+
version: '2.7'
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
|
-
rubygems_version: 3.4.
|
133
|
+
rubygems_version: 3.4.8
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
|