irb 1.6.4 → 1.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db51125adbe98b16228e314bff627b1cec953b92f32c774c4b9a820dc3bfc40b
4
- data.tar.gz: ead3ebf30f5a4369d8cc2767691397d766bab8532031f8f505c2d0b3f251e071
3
+ metadata.gz: d8dc3e14a57010a1ece61f5ca0111e98742f29daea5ab1ad1bdc48e0de6e55b2
4
+ data.tar.gz: 7da9b8c9e3e3c68384c0f65eb030d7874c8f0d07c20ce651ab7b54f5bfdfb9bd
5
5
  SHA512:
6
- metadata.gz: d2f749ce66ed43433fbbc7ec8682a0c3f0180ac8fb676739e5c3cbf0eb2f8bbb89a7896af11120bdeedd730e57edddaeabf932ae22ac55ad33c99f8408ffc832
7
- data.tar.gz: 55621e3a5f9926c3f1b44426c23b9b08543920075fa0d32eeda8b7db35ded09aba6c311011e7f8397a6a5089bbb63d2b2e2603c1d7e254b77a16b93ca35b76f3
6
+ metadata.gz: 73173c7af8ffa50bfa26a49ad1c2b7a2db12a89b006980b2b0d649bc6a03b776359ce03d20a9a7dde493c3c64e70e85864809436b546b571f23e77774748f35e
7
+ data.tar.gz: 371777b42d560af3196092e98555a46d9c93c4efa592e8f38365dd0f5be6863ea4a50d6160baedf7d7d7c6914087394cde33e0fd57e17bec68a63f64f8265a89
data/lib/irb/cmd/help.rb CHANGED
@@ -1,57 +1,23 @@
1
- # frozen_string_literal: false
2
- #
3
- # help.rb - helper using ri
4
- #
1
+ # frozen_string_literal: true
5
2
 
6
- require_relative "nop"
3
+ require_relative "show_doc"
7
4
 
8
5
  module IRB
9
- # :stopdoc:
10
-
11
6
  module ExtendCommand
12
- class Help < Nop
13
- class << self
14
- def transform_args(args)
15
- # Return a string literal as is for backward compatibility
16
- if args.empty? || string_literal?(args)
17
- args
18
- else # Otherwise, consider the input as a String for convenience
19
- args.strip.dump
20
- end
21
- end
22
- end
23
-
7
+ class Help < ShowDoc
24
8
  category "Context"
25
- description "Enter the mode to look up RI documents."
9
+ description "[DEPRECATED] Enter the mode to look up RI documents."
10
+
11
+ DEPRECATION_MESSAGE = <<~MSG
12
+ [Deprecation] The `help` command will be repurposed to display command help in the future.
13
+ For RI document lookup, please use the `show_doc` command instead.
14
+ For command help, please use `show_cmds` for now.
15
+ MSG
26
16
 
27
17
  def execute(*names)
28
- require 'rdoc/ri/driver'
29
- opts = RDoc::RI::Driver.process_args([])
30
- IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new(opts))
31
- rescue LoadError, SystemExit
32
- IRB::ExtendCommand::Help.remove_method(:execute)
33
- # raise NoMethodError in ensure
34
- else
35
- def execute(*names)
36
- if names.empty?
37
- Ri.interactive
38
- return
39
- end
40
- names.each do |name|
41
- begin
42
- Ri.display_name(name.to_s)
43
- rescue RDoc::RI::Error
44
- puts $!.message
45
- end
46
- end
47
- nil
48
- end
49
- nil
50
- ensure
51
- execute(*names)
18
+ warn DEPRECATION_MESSAGE
19
+ super
52
20
  end
53
21
  end
54
22
  end
55
-
56
- # :startdoc:
57
23
  end
@@ -11,24 +11,20 @@ module IRB
11
11
  description "Show information about IRB."
12
12
 
13
13
  def execute
14
- Class.new {
15
- def inspect
16
- str = "Ruby version: #{RUBY_VERSION}\n"
17
- str += "IRB version: #{IRB.version}\n"
18
- str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
19
- str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
20
- str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
21
- str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
22
- str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
23
- str += "East Asian Ambiguous Width: #{Reline.ambiguous_width.inspect}\n"
24
- if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
25
- codepage = `chcp`.b.sub(/.*: (\d+)\n/, '\1')
26
- str += "Code page: #{codepage}\n"
27
- end
28
- str
29
- end
30
- alias_method :to_s, :inspect
31
- }.new
14
+ str = "Ruby version: #{RUBY_VERSION}\n"
15
+ str += "IRB version: #{IRB.version}\n"
16
+ str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
17
+ str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
18
+ str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
19
+ str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
20
+ str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
21
+ str += "East Asian Ambiguous Width: #{Reline.ambiguous_width.inspect}\n"
22
+ if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
23
+ codepage = `chcp`.b.sub(/.*: (\d+)\n/, '\1')
24
+ str += "Code page: #{codepage}\n"
25
+ end
26
+ puts str
27
+ nil
32
28
  end
33
29
  end
34
30
  end
data/lib/irb/cmd/ls.rb CHANGED
@@ -39,8 +39,12 @@ module IRB
39
39
  def dump_methods(o, klass, obj)
40
40
  singleton_class = begin obj.singleton_class; rescue TypeError; nil end
41
41
  dumped_mods = Array.new
42
+ ancestors = klass.ancestors
43
+ ancestors = ancestors.reject { |c| c >= Object } if klass < Object
44
+ singleton_ancestors = (singleton_class&.ancestors || []).reject { |c| c >= Class }
45
+
42
46
  # singleton_class' ancestors should be at the front
43
- maps = class_method_map(singleton_class&.ancestors || [], dumped_mods) + class_method_map(klass.ancestors, dumped_mods)
47
+ maps = class_method_map(singleton_ancestors, dumped_mods) + class_method_map(ancestors, dumped_mods)
44
48
  maps.each do |mod, methods|
45
49
  name = mod == singleton_class ? "#{klass}.methods" : "#{mod}#methods"
46
50
  o.dump(name, methods)
@@ -49,7 +53,6 @@ module IRB
49
53
 
50
54
  def class_method_map(classes, dumped_mods)
51
55
  dumped_methods = Array.new
52
- classes = classes.reject { |mod| mod >= Object }
53
56
  classes.map do |mod|
54
57
  next if dumped_mods.include? mod
55
58
 
data/lib/irb/cmd/nop.rb CHANGED
@@ -30,23 +30,19 @@ module IRB
30
30
  end
31
31
  end
32
32
 
33
- def self.execute(conf, *opts, **kwargs, &block)
34
- command = new(conf)
33
+ def self.execute(irb_context, *opts, **kwargs, &block)
34
+ command = new(irb_context)
35
35
  command.execute(*opts, **kwargs, &block)
36
36
  rescue CommandArgumentError => e
37
37
  puts e.message
38
38
  end
39
39
 
40
- def initialize(conf)
41
- @irb_context = conf
40
+ def initialize(irb_context)
41
+ @irb_context = irb_context
42
42
  end
43
43
 
44
44
  attr_reader :irb_context
45
45
 
46
- def irb
47
- @irb_context.irb
48
- end
49
-
50
46
  def execute(*opts)
51
47
  #nop
52
48
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "nop"
4
+
5
+ module IRB
6
+ module ExtendCommand
7
+ class ShowDoc < Nop
8
+ class << self
9
+ def transform_args(args)
10
+ # Return a string literal as is for backward compatibility
11
+ if args.empty? || string_literal?(args)
12
+ args
13
+ else # Otherwise, consider the input as a String for convenience
14
+ args.strip.dump
15
+ end
16
+ end
17
+ end
18
+
19
+ category "Context"
20
+ description "Enter the mode to look up RI documents."
21
+
22
+ def execute(*names)
23
+ require 'rdoc/ri/driver'
24
+
25
+ unless ShowDoc.const_defined?(:Ri)
26
+ opts = RDoc::RI::Driver.process_args([])
27
+ ShowDoc.const_set(:Ri, RDoc::RI::Driver.new(opts))
28
+ end
29
+
30
+ if names.empty?
31
+ Ri.interactive
32
+ else
33
+ names.each do |name|
34
+ begin
35
+ Ri.display_name(name.to_s)
36
+ rescue RDoc::RI::Error
37
+ puts $!.message
38
+ end
39
+ end
40
+ end
41
+
42
+ nil
43
+ rescue LoadError, SystemExit
44
+ warn "Can't display document because `rdoc` is not installed."
45
+ end
46
+ end
47
+ end
48
+ end
@@ -31,13 +31,14 @@ module IRB
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]
34
- if owner.respond_to?(:instance_method) && owner.instance_methods.include?(method.to_sym)
35
- file, line = owner.instance_method(method).source_location
34
+ if owner.respond_to?(:instance_method)
35
+ methods = owner.instance_methods + owner.private_instance_methods
36
+ file, line = owner.instance_method(method).source_location if methods.include?(method.to_sym)
36
37
  end
37
38
  when /\A((?<receiver>.+)(\.|::))?(?<method>[^ :.]+)\z/ # method, receiver.method, receiver::method
38
39
  receiver = eval(Regexp.last_match[:receiver] || 'self', irb_context.workspace.binding)
39
40
  method = Regexp.last_match[:method]
40
- file, line = receiver.method(method).source_location if receiver.respond_to?(method)
41
+ file, line = receiver.method(method).source_location if receiver.respond_to?(method, true)
41
42
  end
42
43
  if file && line
43
44
  Source.new(file: file, first_line: line, last_line: find_end(file, line, irb_context))
@@ -57,9 +58,9 @@ module IRB
57
58
  tokens.chunk { |tok| tok.pos[0] }.each do |lnum, chunk|
58
59
  code = lines[0..lnum].join
59
60
  prev_tokens.concat chunk
60
- continue = lex.process_continue(prev_tokens)
61
- code_block_open = lex.check_code_block(code, prev_tokens)
62
- if !continue && !code_block_open
61
+ continue = lex.should_continue?(prev_tokens)
62
+ syntax = lex.check_code_syntax(code)
63
+ if !continue && syntax == :valid
63
64
  return first_line + lnum
64
65
  end
65
66
  end
@@ -218,7 +218,7 @@ module IRB
218
218
  else
219
219
  sym = $1
220
220
  candidates = Symbol.all_symbols.collect do |s|
221
- ":" + s.id2name.encode(Encoding.default_external)
221
+ s.inspect
222
222
  rescue EncodingError
223
223
  # ignore
224
224
  end
@@ -233,7 +233,7 @@ module IRB
233
233
  if doc_namespace
234
234
  candidates.find { |i| i == receiver }
235
235
  else
236
- candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
236
+ candidates.grep(/^#{Regexp.quote(receiver)}/).collect{|e| "::" + e}
237
237
  end
238
238
 
239
239
  when /^([A-Z].*)::([^:.]*)$/
data/lib/irb/context.rb CHANGED
@@ -473,28 +473,31 @@ module IRB
473
473
  @inspect_mode
474
474
  end
475
475
 
476
- def evaluate(line, line_no, exception: nil) # :nodoc:
476
+ def evaluate(line, line_no) # :nodoc:
477
477
  @line_no = line_no
478
- if exception
479
- line_no -= 1
480
- line = "begin ::Kernel.raise _; rescue _.class\n#{line}\n""end"
481
- @workspace.local_variable_set(:_, exception)
482
- end
478
+ result = nil
483
479
 
484
- # Transform a non-identifier alias (@, $) or keywords (next, break)
485
- command, args = line.split(/\s/, 2)
486
- if original = command_aliases[command.to_sym]
487
- line = line.gsub(/\A#{Regexp.escape(command)}/, original.to_s)
488
- command = original
480
+ if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty?
481
+ IRB.set_measure_callback
489
482
  end
490
483
 
491
- # Hook command-specific transformation
492
- command_class = ExtendCommandBundle.load_command(command)
493
- if command_class&.respond_to?(:transform_args)
494
- line = "#{command} #{command_class.transform_args(args)}"
484
+ if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
485
+ last_proc = proc do
486
+ result = @workspace.evaluate(line, irb_path, line_no)
487
+ end
488
+ IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) do |chain, item|
489
+ _name, callback, arg = item
490
+ proc do
491
+ callback.(self, line, line_no, arg) do
492
+ chain.call
493
+ end
494
+ end
495
+ end.call
496
+ else
497
+ result = @workspace.evaluate(line, irb_path, line_no)
495
498
  end
496
499
 
497
- set_last_value(@workspace.evaluate(line, irb_path, line_no))
500
+ set_last_value(result)
498
501
  end
499
502
 
500
503
  def inspect_last_value # :nodoc:
@@ -42,6 +42,7 @@ module IRB # :nodoc:
42
42
  #
43
43
  # See Irb#suspend_input_method for more information.
44
44
  def source_file(path)
45
+ irb = irb_context.irb
45
46
  irb.suspend_name(path, File.basename(path)) do
46
47
  FileInputMethod.open(path) do |io|
47
48
  irb.suspend_input_method(io) do
@@ -66,6 +67,7 @@ module IRB # :nodoc:
66
67
  #
67
68
  # See Irb#suspend_input_method for more information.
68
69
  def load_file(path, priv = nil)
70
+ irb = irb_context.irb
69
71
  irb.suspend_name(path, File.basename(path)) do
70
72
 
71
73
  if priv
@@ -7,7 +7,7 @@
7
7
  begin
8
8
  require "tracer"
9
9
  rescue LoadError
10
- $stderr.puts "Tracer extension of IRB is enabled but tracer gem doesn't found."
10
+ $stderr.puts "Tracer extension of IRB is enabled but tracer gem wasn't found."
11
11
  module IRB
12
12
  class Context
13
13
  def use_tracer=(opt)
@@ -157,10 +157,14 @@ module IRB # :nodoc:
157
157
 
158
158
  [
159
159
  :irb_help, :Help, "cmd/help",
160
- [:show_doc, NO_OVERRIDE],
161
160
  [:help, NO_OVERRIDE],
162
161
  ],
163
162
 
163
+ [
164
+ :irb_show_doc, :ShowDoc, "cmd/show_doc",
165
+ [:show_doc, NO_OVERRIDE],
166
+ ],
167
+
164
168
  [
165
169
  :irb_info, :IrbInfo, "cmd/irb_info"
166
170
  ],
@@ -285,7 +289,7 @@ module IRB # :nodoc:
285
289
  alias_method to, from
286
290
  }
287
291
  else
288
- Kernel.print "irb: warn: can't alias #{to} from #{from}.\n"
292
+ Kernel.warn "irb: warn: can't alias #{to} from #{from}.\n"
289
293
  end
290
294
  end
291
295
 
data/lib/irb/help.rb CHANGED
@@ -4,15 +4,13 @@
4
4
  # by Keiju ISHITSUKA(keiju@ishitsuka.com)
5
5
  #
6
6
 
7
- require_relative 'magic-file'
8
-
9
7
  module IRB
10
8
  # Outputs the irb help message, see IRB@Command+line+options.
11
9
  def IRB.print_usage
12
10
  lc = IRB.conf[:LC_MESSAGES]
13
11
  path = lc.find("irb/help-message")
14
12
  space_line = false
15
- IRB::MagicFile.open(path){|f|
13
+ File.open(path){|f|
16
14
  f.each_line do |l|
17
15
  if /^\s*$/ =~ l
18
16
  lc.puts l unless space_line
@@ -5,7 +5,6 @@
5
5
  #
6
6
 
7
7
  require_relative 'src_encoding'
8
- require_relative 'magic-file'
9
8
  require_relative 'completion'
10
9
  require 'io/console'
11
10
  require 'reline'
@@ -132,7 +131,7 @@ module IRB
132
131
  # Creates a new input method object
133
132
  def initialize(file)
134
133
  super
135
- @io = file.is_a?(IO) ? file : IRB::MagicFile.open(file)
134
+ @io = file.is_a?(IO) ? file : File.open(file)
136
135
  @external_encoding = @io.external_encoding
137
136
  end
138
137
  # The file name of this input method, usually given during initialization.
@@ -399,8 +398,10 @@ module IRB
399
398
  formatter = RDoc::Markup::ToAnsi.new
400
399
  formatter.width = width
401
400
  dialog.trap_key = alt_d
402
- message = 'Press Alt+d to read the full document'
401
+ mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
402
+ message = "Press #{mod_key}+d to read the full document"
403
403
  contents = [message] + doc.accept(formatter).split("\n")
404
+ contents = contents.take(preferred_dialog_height) if respond_to?(:preferred_dialog_height)
404
405
 
405
406
  y = cursor_pos_to_render.y
406
407
  DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
data/lib/irb/locale.rb CHANGED
@@ -15,7 +15,11 @@ module IRB # :nodoc:
15
15
  ]x
16
16
  LOCALE_DIR = "/lc/"
17
17
 
18
- @@legacy_encoding_alias_map = {}.freeze
18
+ LEGACY_ENCODING_ALIAS_MAP = {
19
+ 'ujis' => Encoding::EUC_JP,
20
+ 'euc' => Encoding::EUC_JP
21
+ }
22
+
19
23
  @@loaded = []
20
24
 
21
25
  def initialize(locale = nil)
@@ -26,11 +30,11 @@ module IRB # :nodoc:
26
30
  @lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
27
31
 
28
32
  if @encoding_name
29
- begin load 'irb/encoding_aliases.rb'; rescue LoadError; end
30
- if @encoding = @@legacy_encoding_alias_map[@encoding_name]
33
+ if @encoding = LEGACY_ENCODING_ALIAS_MAP[@encoding_name]
31
34
  warn(("%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]), uplevel: 1)
35
+ else
36
+ @encoding = Encoding.find(@encoding_name) rescue nil
32
37
  end
33
- @encoding = Encoding.find(@encoding_name) rescue nil
34
38
  end
35
39
  end
36
40
  @encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
@@ -78,39 +82,12 @@ module IRB # :nodoc:
78
82
  super(*ary)
79
83
  end
80
84
 
81
- def require(file, priv = nil)
82
- rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
83
- return false if $".find{|f| f =~ rex}
84
-
85
- case file
86
- when /\.rb$/
87
- begin
88
- load(file, priv)
89
- $".push file
90
- return true
91
- rescue LoadError
92
- end
93
- when /\.(so|o|sl)$/
94
- return super
95
- end
96
-
97
- begin
98
- load(f = file + ".rb")
99
- $".push f #"
100
- return true
101
- rescue LoadError
102
- return ruby_require(file)
103
- end
104
- end
105
-
106
- alias toplevel_load load
107
-
108
- def load(file, priv=nil)
85
+ def load(file)
109
86
  found = find(file)
110
87
  if found
111
88
  unless @@loaded.include?(found)
112
89
  @@loaded << found # cache
113
- return real_load(found, priv)
90
+ Kernel.load(found)
114
91
  end
115
92
  else
116
93
  raise LoadError, "No such file to load -- #{file}"
@@ -129,16 +106,6 @@ module IRB # :nodoc:
129
106
  end
130
107
  end
131
108
 
132
- private
133
- def real_load(path, priv)
134
- src = MagicFile.open(path){|f| f.read}
135
- if priv
136
- eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
137
- else
138
- eval(src, TOPLEVEL_BINDING, path)
139
- end
140
- end
141
-
142
109
  # @param paths load paths in which IRB find a localized file.
143
110
  # @param dir directory
144
111
  # @param file basename to be localized