irb 1.3.8.pre.6 → 1.3.8.pre.10

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: 06b92bc1578697f4b6e2b861b6c30acd6fa0c90abe522d32c61b50575564e3d2
4
- data.tar.gz: 3723d32bd956638ace71443964cd4d7658874bdb4332d9384be27785668ff787
3
+ metadata.gz: 64245fa0213491e1a1340223cad9978a831a4cb95c30583947d1580f781fa916
4
+ data.tar.gz: 971cb2a3ef3631d3489202f13e070c43966d4e981dae846ca2756248afb2285f
5
5
  SHA512:
6
- metadata.gz: 9eb5a314af921a15b7bb04812f83d90ddbf7bb8bbd22ec2ef8591bd796d12999d4921df8eaf7076bd7d721ce0998c9c3ddbafcdc1e732e009244812694d8703f
7
- data.tar.gz: 7772cb563cdbfd9b13e69dd0f2e3665a559983d95a5dbd5e51bf8624a2c8ed10983d6e29a6468b92743a686a3dcf1441b32c42c58f70e5e8634a93144370e232
6
+ metadata.gz: 1547d50d86acaeeb7edc4dc0d68fd9cf2f025f82f1f7e47728d8212776506cd485dcd96c39c5b429e8b7c2f83afc1698042b976797fa2e26d4ba2b4faba7e186
7
+ data.tar.gz: d18b3174329d2c7f253dfcfbff40656ceaf2fd42fa603468e0bb48eba6e4057c6e5fdc06874f1d7701f5be47d072aa0aa2b024bdb7e8a80e6644041e2af5b03e
data/doc/irb/irb.rd.ja CHANGED
@@ -51,6 +51,12 @@ irbの使い方は, Rubyさえ知っていればいたって簡単です. 基本
51
51
  オブジェクトの作成方法を 0 から 3 のいずれかに設定する.
52
52
  --echo 実行結果を表示する(デフォルト).
53
53
  --noecho 実行結果を表示しない.
54
+ --echo-on-assignment
55
+ 代入時に実行結果を表示する.
56
+ --noecho-on-assignment
57
+ 代入時に実行結果を表示しない.
58
+ --truncate-echo-on-assignment
59
+ 代入時に省略された実行結果を表示する(デフォルト).
54
60
  --inspect 結果出力にinspectを用いる.
55
61
  --noinspect 結果出力にinspectを用いない.
56
62
  --singleline シングルラインエディタを利用する.
data/irb.gemspec CHANGED
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
36
36
 
37
37
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5")
38
38
 
39
- spec.add_dependency "reline", ">= 0.2.8.pre.6"
39
+ spec.add_dependency "reline", ">= 0.2.8.pre.10"
40
40
  end
data/lib/irb/cmd/help.rb CHANGED
@@ -17,7 +17,8 @@ module IRB
17
17
  class Help < Nop
18
18
  def execute(*names)
19
19
  require 'rdoc/ri/driver'
20
- IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new)
20
+ opts = RDoc::RI::Driver.process_args([])
21
+ IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new(opts))
21
22
  rescue LoadError, SystemExit
22
23
  IRB::ExtendCommand::Help.remove_method(:execute)
23
24
  # raise NoMethodError in ensure
@@ -38,16 +38,48 @@ module IRB
38
38
 
39
39
  BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
40
40
 
41
- def self.retrieve_files_to_require_from_load_path
42
- @@files_from_load_path ||= $LOAD_PATH.flat_map { |path|
43
- begin
44
- Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
45
- rescue Errno::ENOENT
46
- []
41
+ def self.absolute_path?(p) # TODO Remove this method after 2.6 EOL.
42
+ if File.respond_to?(:absolute_path?)
43
+ File.absolute_path?(p)
44
+ else
45
+ if File.absolute_path(p) == p
46
+ true
47
+ else
48
+ false
47
49
  end
48
- }.uniq.map { |path|
49
- path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
50
- }
50
+ end
51
+ end
52
+
53
+ def self.retrieve_gem_and_system_load_path
54
+ gem_paths = Gem::Specification.latest_specs(true).map { |s|
55
+ s.require_paths.map { |p|
56
+ if absolute_path?(p)
57
+ p
58
+ else
59
+ File.join(s.full_gem_path, p)
60
+ end
61
+ }
62
+ }.flatten if defined?(Gem::Specification)
63
+ (gem_paths.to_a | $LOAD_PATH).sort
64
+ end
65
+
66
+ def self.retrieve_files_to_require_from_load_path
67
+ @@files_from_load_path ||=
68
+ (
69
+ shortest = []
70
+ rest = retrieve_gem_and_system_load_path.each_with_object([]) { |path, result|
71
+ begin
72
+ names = Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
73
+ rescue Errno::ENOENT
74
+ nil
75
+ end
76
+ next if names.empty?
77
+ names.map! { |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort!
78
+ shortest << names.shift
79
+ result.concat(names)
80
+ }
81
+ shortest.sort! | rest
82
+ )
51
83
  end
52
84
 
53
85
  def self.retrieve_files_to_require_relative_from_current_dir
@@ -160,7 +192,7 @@ module IRB
160
192
  sym = $1
161
193
  candidates = Symbol.all_symbols.collect do |s|
162
194
  ":" + s.id2name.encode(Encoding.default_external)
163
- rescue Encoding::UndefinedConversionError
195
+ rescue EncodingError
164
196
  # ignore
165
197
  end
166
198
  candidates.grep(/^#{Regexp.quote(sym)}/)
@@ -258,7 +290,7 @@ module IRB
258
290
  all_gvars.grep(Regexp.new(Regexp.quote(gvar)))
259
291
  end
260
292
 
261
- when /^([^."].*)(\.|::)([^.]*)$/
293
+ when /^([^.:"].*)(\.|::)([^.]*)$/
262
294
  # variable.func or func.func
263
295
  receiver = $1
264
296
  sep = $2
@@ -296,7 +328,8 @@ module IRB
296
328
  candidates.uniq!
297
329
  end
298
330
  if doc_namespace
299
- "#{rec.class.name}#{sep}#{candidates.find{ |i| i == message }}"
331
+ rec_class = rec.is_a?(Module) ? rec : rec.class
332
+ "#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
300
333
  else
301
334
  select_message(receiver, message, candidates, sep)
302
335
  end
data/lib/irb/context.rb CHANGED
@@ -264,13 +264,28 @@ module IRB
264
264
  #
265
265
  # a = "omg"
266
266
  # #=> omg
267
+ #
267
268
  # a = "omg" * 10
268
269
  # #=> omgomgomgomgomgomgomg...
270
+ #
269
271
  # IRB.CurrentContext.echo_on_assignment = false
270
272
  # a = "omg"
273
+ #
271
274
  # IRB.CurrentContext.echo_on_assignment = true
272
- # a = "omg"
275
+ # a = "omg" * 10
273
276
  # #=> omgomgomgomgomgomgomgomgomgomg
277
+ #
278
+ # To set the behaviour of showing on assignment in irb:
279
+ #
280
+ # IRB.conf[:ECHO_ON_ASSIGNMENT] = :truncate or true or false
281
+ #
282
+ # or
283
+ #
284
+ # irb_context.echo_on_assignment = :truncate or true or false
285
+ #
286
+ # or
287
+ #
288
+ # IRB.CurrentContext.echo_on_assignment = :truncate or true or false
274
289
  attr_accessor :echo_on_assignment
275
290
  # Whether a newline is put before multiline output.
276
291
  #
@@ -314,11 +314,17 @@ module IRB
314
314
  end
315
315
 
316
316
  SHOW_DOC_DIALOG = ->() {
317
+ dialog.trap_key = nil
318
+ alt_d = [
319
+ [Reline::Key.new(nil, 0xE4, true)], # Normal Alt+d.
320
+ [195, 164] # The "ä" that appears when Alt+d is pressed on xterm.
321
+ ]
317
322
  begin
318
323
  require 'rdoc'
319
324
  rescue LoadError
320
325
  return nil
321
326
  end
327
+
322
328
  if just_cursor_moving and completion_journey_data.nil?
323
329
  return nil
324
330
  end
@@ -328,6 +334,14 @@ module IRB
328
334
  name = IRB::InputCompletor.retrieve_completion_data(name, doc_namespace: true)
329
335
 
330
336
  driver = RDoc::RI::Driver.new
337
+
338
+ if key.match?(dialog.name)
339
+ begin
340
+ driver.display_names([name])
341
+ rescue RDoc::RI::Driver::NotFoundError
342
+ end
343
+ end
344
+
331
345
  begin
332
346
  name = driver.expand_name(name)
333
347
  rescue RDoc::RI::Driver::NotFoundError
@@ -358,7 +372,9 @@ module IRB
358
372
  width = 40
359
373
  formatter = RDoc::Markup::ToAnsi.new
360
374
  formatter.width = width
361
- contents = doc.accept(formatter).split("\n")
375
+ dialog.trap_key = alt_d
376
+ message = 'Press Alt+d to read the full document'
377
+ contents = [message] + doc.accept(formatter).split("\n")
362
378
 
363
379
  x = cursor_pos_to_render.x + autocomplete_dialog.width
364
380
  x = autocomplete_dialog.column - width if x + width >= screen_width
@@ -20,8 +20,14 @@ Usage: irb.rb [options] [programfile] [arguments]
20
20
  -W[level=2] Same as `ruby -W`
21
21
  --context-mode n Set n[0-4] to method to create Binding Object,
22
22
  when new workspace was created
23
- --echo Show result(default)
23
+ --echo Show result (default)
24
24
  --noecho Don't show result
25
+ --echo-on-assignment
26
+ Show result on assignment
27
+ --noecho-on-assignment
28
+ Don't show result on assignment
29
+ --truncate-echo-on-assignment
30
+ Show truncated result on assignment (default)
25
31
  --inspect Use `inspect' for output
26
32
  --noinspect Don't use inspect for output
27
33
  --multiline Use multiline editor module
data/lib/irb/ruby-lex.rb CHANGED
@@ -207,7 +207,7 @@ class RubyLex
207
207
  last_line = lines[line_index]&.byteslice(0, byte_pointer)
208
208
  code += last_line if last_line
209
209
  @tokens = self.class.ripper_lex_without_warning(code, context: context)
210
- corresponding_token_depth = check_corresponding_token_depth
210
+ corresponding_token_depth = check_corresponding_token_depth(lines, line_index)
211
211
  if corresponding_token_depth
212
212
  corresponding_token_depth
213
213
  else
@@ -603,7 +603,7 @@ class RubyLex
603
603
  depth_difference
604
604
  end
605
605
 
606
- def check_corresponding_token_depth
606
+ def check_corresponding_token_depth(lines, line_index)
607
607
  corresponding_token_depth = nil
608
608
  is_first_spaces_of_line = true
609
609
  is_first_printable_of_line = true
@@ -611,6 +611,11 @@ class RubyLex
611
611
  spaces_at_line_head = 0
612
612
  open_brace_on_line = 0
613
613
  in_oneliner_def = nil
614
+
615
+ if heredoc_scope?
616
+ return lines[line_index][/^ */].length
617
+ end
618
+
614
619
  @tokens.each_with_index do |t, index|
615
620
  # detecting one-liner method definition
616
621
  if in_oneliner_def.nil?
@@ -708,6 +713,9 @@ class RubyLex
708
713
  while i < tokens.size
709
714
  t = tokens[i]
710
715
  case t[1]
716
+ when *end_type.last
717
+ start_token.pop
718
+ end_type.pop
711
719
  when :on_tstring_beg
712
720
  start_token << t
713
721
  end_type << [:on_tstring_end, :on_label_end]
@@ -715,10 +723,14 @@ class RubyLex
715
723
  start_token << t
716
724
  end_type << :on_regexp_end
717
725
  when :on_symbeg
718
- acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw on_int}
719
- if (i + 1) < tokens.size and acceptable_single_tokens.all?{ |st| tokens[i + 1][1] != st }
720
- start_token << t
721
- end_type << :on_tstring_end
726
+ acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw on_int on_backtick}
727
+ if (i + 1) < tokens.size
728
+ if acceptable_single_tokens.all?{ |st| tokens[i + 1][1] != st }
729
+ start_token << t
730
+ end_type << :on_tstring_end
731
+ else
732
+ i += 1
733
+ end
722
734
  end
723
735
  when :on_backtick
724
736
  start_token << t
@@ -729,9 +741,6 @@ class RubyLex
729
741
  when :on_heredoc_beg
730
742
  start_token << t
731
743
  end_type << :on_heredoc_end
732
- when *end_type.last
733
- start_token.pop
734
- end_type.pop
735
744
  end
736
745
  i += 1
737
746
  end
@@ -813,5 +822,12 @@ class RubyLex
813
822
  end
814
823
  false
815
824
  end
825
+
826
+ private
827
+
828
+ def heredoc_scope?
829
+ heredoc_tokens = @tokens.select { |t| [:on_heredoc_beg, :on_heredoc_end].include?(t.event) }
830
+ heredoc_tokens[-1]&.event == :on_heredoc_beg
831
+ end
816
832
  end
817
833
  # :startdoc:
data/lib/irb/version.rb CHANGED
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module IRB # :nodoc:
14
- VERSION = "1.3.8.pre.6"
14
+ VERSION = "1.3.8.pre.10"
15
15
  @RELEASE_VERSION = VERSION
16
- @LAST_UPDATE_DATE = "2021-09-02"
16
+ @LAST_UPDATE_DATE = "2021-10-03"
17
17
  end
data/lib/irb/workspace.rb CHANGED
@@ -12,6 +12,7 @@
12
12
 
13
13
  require "delegate"
14
14
 
15
+ IRB::TOPLEVEL_BINDING = binding
15
16
  module IRB # :nodoc:
16
17
  class WorkSpace
17
18
  # Creates a new workspace.
@@ -57,6 +58,8 @@ EOF
57
58
  __FILE__,
58
59
  __LINE__ - 3)
59
60
  when 4 # binding is a copy of TOPLEVEL_BINDING (default)
61
+ # Note that this will typically be IRB::TOPLEVEL_BINDING
62
+ # This is to avoid RubyGems' local variables (see issue #17623)
60
63
  @binding = TOPLEVEL_BINDING.dup
61
64
  end
62
65
  end
data/lib/irb.rb CHANGED
@@ -62,8 +62,14 @@ require_relative "irb/easter-egg"
62
62
  # -W[level=2] Same as `ruby -W`
63
63
  # --context-mode n Set n[0-4] to method to create Binding Object,
64
64
  # when new workspace was created
65
- # --echo Show result(default)
65
+ # --echo Show result (default)
66
66
  # --noecho Don't show result
67
+ # --echo-on-assignment
68
+ # Show result on assignment
69
+ # --noecho-on-assignment
70
+ # Don't show result on assignment
71
+ # --truncate-echo-on-assignment
72
+ # Show truncated result on assignment (default)
67
73
  # --inspect Use `inspect' for output
68
74
  # --noinspect Don't use inspect for output
69
75
  # --multiline Use multiline editor module
@@ -669,6 +675,8 @@ module IRB
669
675
  lines = lines.reverse if order == :bottom
670
676
  lines.map{ |l| l + "\n" }.join
671
677
  }
678
+ # The "<top (required)>" in "(irb)" may be the top level of IRB so imitate the main object.
679
+ message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
672
680
  puts message
673
681
  end
674
682
  print "Maybe IRB bug!\n" if irb_bug
data/man/irb.1 CHANGED
@@ -106,12 +106,22 @@ Doesn't use singleline editor module.
106
106
  .Pp
107
107
  .Pp
108
108
  .It Fl -echo
109
- Show result(default).
109
+ Show result (default).
110
110
  .Pp
111
111
  .It Fl -noecho
112
112
  Don't show result.
113
113
  .Pp
114
114
  .Pp
115
+ .It Fl -echo-on-assignment
116
+ Show result on assignment.
117
+ .Pp
118
+ .It Fl -noecho-on-assignment
119
+ Don't show result on assignment.
120
+ .Pp
121
+ .It Fl -truncate-echo-on-assignment
122
+ Show truncated result on assignment (default).
123
+ .Pp
124
+ .Pp
115
125
  .It Fl -colorize
116
126
  Use colorization.
117
127
  .Pp
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.8.pre.6
4
+ version: 1.3.8.pre.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keiju ISHITSUKA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-02 00:00:00.000000000 Z
11
+ date: 2021-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reline
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.8.pre.6
19
+ version: 0.2.8.pre.10
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.8.pre.6
26
+ version: 0.2.8.pre.10
27
27
  description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
28
28
  email:
29
29
  - keiju@ruby-lang.org