irb 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -8
  3. data/lib/irb/cmd/nop.rb +3 -52
  4. data/lib/irb/{cmd → command}/backtrace.rb +1 -1
  5. data/lib/irb/command/base.rb +64 -0
  6. data/lib/irb/{cmd → command}/break.rb +1 -1
  7. data/lib/irb/{cmd → command}/catch.rb +1 -1
  8. data/lib/irb/{cmd → command}/chws.rb +4 -6
  9. data/lib/irb/{cmd → command}/continue.rb +1 -1
  10. data/lib/irb/{cmd → command}/debug.rb +3 -4
  11. data/lib/irb/{cmd → command}/delete.rb +1 -1
  12. data/lib/irb/command/edit.rb +70 -0
  13. data/lib/irb/{cmd → command}/exit.rb +2 -4
  14. data/lib/irb/{cmd → command}/finish.rb +1 -1
  15. data/lib/irb/command/force_exit.rb +20 -0
  16. data/lib/irb/command/help.rb +84 -0
  17. data/lib/irb/{cmd → command}/history.rb +3 -3
  18. data/lib/irb/{cmd → command}/info.rb +1 -1
  19. data/lib/irb/{cmd → command}/irb_info.rb +5 -6
  20. data/lib/irb/{cmd → command}/load.rb +3 -5
  21. data/lib/irb/{cmd → command}/ls.rb +10 -4
  22. data/lib/irb/{cmd → command}/measure.rb +2 -4
  23. data/lib/irb/{cmd → command}/next.rb +1 -1
  24. data/lib/irb/{cmd → command}/pushws.rb +20 -5
  25. data/lib/irb/{cmd → command}/show_doc.rb +17 -5
  26. data/lib/irb/{cmd → command}/show_source.rb +26 -10
  27. data/lib/irb/{cmd → command}/step.rb +1 -1
  28. data/lib/irb/{cmd → command}/subirb.rb +3 -5
  29. data/lib/irb/{cmd → command}/whereami.rb +2 -4
  30. data/lib/irb/{extend-command.rb → command.rb} +50 -85
  31. data/lib/irb/completion.rb +1 -1
  32. data/lib/irb/context.rb +56 -18
  33. data/lib/irb/ext/change-ws.rb +4 -4
  34. data/lib/irb/ext/eval_history.rb +3 -3
  35. data/lib/irb/ext/loader.rb +4 -4
  36. data/lib/irb/ext/multi-irb.rb +1 -1
  37. data/lib/irb/ext/tracer.rb +1 -1
  38. data/lib/irb/ext/use-loader.rb +6 -8
  39. data/lib/irb/ext/workspaces.rb +11 -34
  40. data/lib/irb/frame.rb +1 -1
  41. data/lib/irb/help.rb +1 -1
  42. data/lib/irb/history.rb +2 -2
  43. data/lib/irb/init.rb +22 -14
  44. data/lib/irb/input-method.rb +18 -2
  45. data/lib/irb/inspector.rb +2 -2
  46. data/lib/irb/lc/error.rb +1 -6
  47. data/lib/irb/lc/ja/error.rb +1 -6
  48. data/lib/irb/locale.rb +1 -1
  49. data/lib/irb/notifier.rb +1 -1
  50. data/lib/irb/output-method.rb +2 -8
  51. data/lib/irb/ruby-lex.rb +1 -1
  52. data/lib/irb/source_finder.rb +98 -38
  53. data/lib/irb/statement.rb +25 -3
  54. data/lib/irb/version.rb +3 -3
  55. data/lib/irb/workspace.rb +4 -4
  56. data/lib/irb/ws-for-case-2.rb +1 -1
  57. data/lib/irb/xmp.rb +1 -1
  58. data/lib/irb.rb +29 -22
  59. metadata +30 -29
  60. data/lib/irb/cmd/edit.rb +0 -60
  61. data/lib/irb/cmd/help.rb +0 -23
  62. data/lib/irb/cmd/show_cmds.rb +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53ffdc8550a2c9debc40dc6565f23010c02959bf924fc917a6736465960dc660
4
- data.tar.gz: ca6f06898a6b431303c5b63b9f8ff88295106ad66d8cb30e85a6f5f879449c8e
3
+ metadata.gz: 4ef257bd1b4917c3af8f4e1c372cb7c489cd16844df518e352c0bff74c77b4fc
4
+ data.tar.gz: e9cd328330de9c415b93f680228ff79c3a798c481fe657bc48f7d7305470462c
5
5
  SHA512:
6
- metadata.gz: '059eb872f0be29fec2c8fe7c64b809f9346b3e25b084a1033ab4ea6e02e7c3e311317d2a169a18d5a9291acc578e56c1587c12f901d2e09fa52d58fe3717377c'
7
- data.tar.gz: 8b6cce5c6bc85f25db7a78977e433746efa47d2eb0b0828d9adebb813ce0648396aae6e0c903aca30b79f2c1e947f319e75b21e916eb6f8a8a8f8d5553431d5c
6
+ metadata.gz: 78b5b33588812cda49274b45e7b905cec8cb9e6b0ed71be66a644680db5ac96a19e276952425ec54a05d2ce3e8cf99b69eb7964e310770e155ced4f51501b088
7
+ data.tar.gz: 68ae7b61704a3356a14d526bdf058306c9ef158d8442030779b9256a59bee2929e1bab1fdf394f39bda09479b47430ca1de94c57c7b23017affec1400975e03a
data/README.md CHANGED
@@ -30,7 +30,7 @@ The `irb` command from your shell will start the interpreter.
30
30
 
31
31
  ## Installation
32
32
 
33
- > **Note**
33
+ > [!Note]
34
34
  >
35
35
  > IRB is a default gem of Ruby so you shouldn't need to install it separately.
36
36
  >
@@ -56,7 +56,7 @@ $ gem install irb
56
56
 
57
57
  ## Usage
58
58
 
59
- > **Note**
59
+ > [!Note]
60
60
  >
61
61
  > We're working hard to match Pry's variety of powerful features in IRB, and you can track our progress or find contribution ideas in [this document](https://github.com/ruby/irb/blob/master/COMPARED_WITH_PRY.md).
62
62
 
@@ -107,16 +107,19 @@ Hello World
107
107
 
108
108
  ## Commands
109
109
 
110
- The following commands are available on IRB. You can get the same output from the `show_cmds` command.
110
+ The following commands are available on IRB. You can get the same output from the `help` command.
111
111
 
112
112
  ```txt
113
+ Help
114
+ help List all available commands. Use `help <command>` to get information about a specific command.
115
+
113
116
  IRB
114
117
  exit Exit the current irb session.
118
+ exit! Exit the current process.
115
119
  irb_load Load a Ruby file.
116
120
  irb_require Require a Ruby file.
117
121
  source Loads a given file in the current session.
118
122
  irb_info Show information about IRB.
119
- show_cmds List all available commands and their description.
120
123
  history Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output.
121
124
 
122
125
  Workspace
@@ -145,13 +148,12 @@ Debugging
145
148
  info Start the debugger of debug.gem and run its `info` command.
146
149
 
147
150
  Misc
148
- edit Open a file with the editor command defined with `ENV["VISUAL"]` or `ENV["EDITOR"]`.
151
+ edit Open a file or source location.
149
152
  measure `measure` enables the mode to measure processing time. `measure :off` disables it.
150
153
 
151
154
  Context
152
- help [DEPRECATED] Enter the mode to look up RI documents.
153
155
  show_doc Enter the mode to look up RI documents.
154
- ls Show methods, constants, and variables. `-g [query]` or `-G [query]` allows you to filter out the output.
156
+ ls Show methods, constants, and variables.
155
157
  show_source Show the source code of a given method or constant.
156
158
  whereami Show the source code around binding.irb again.
157
159
 
@@ -227,7 +229,7 @@ end
227
229
 
228
230
  To learn about these features, please refer to `debug.gem`'s [commands list](https://github.com/ruby/debug#debug-command-on-the-debug-console).
229
231
 
230
- In the `irb:rdbg` session, the `show_cmds` command will also display all commands from `debug.gem`.
232
+ In the `irb:rdbg` session, the `help` command will also display all commands from `debug.gem`.
231
233
 
232
234
  ### Advantages Over `debug.gem`'s Console
233
235
 
data/lib/irb/cmd/nop.rb CHANGED
@@ -1,53 +1,4 @@
1
- # frozen_string_literal: false
2
- #
3
- # nop.rb -
4
- # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
- #
1
+ # frozen_string_literal: true
6
2
 
7
- module IRB
8
- # :stopdoc:
9
-
10
- module ExtendCommand
11
- class CommandArgumentError < StandardError; end
12
-
13
- class Nop
14
- class << self
15
- def category(category = nil)
16
- @category = category if category
17
- @category
18
- end
19
-
20
- def description(description = nil)
21
- @description = description if description
22
- @description
23
- end
24
-
25
- private
26
-
27
- def string_literal?(args)
28
- sexp = Ripper.sexp(args)
29
- sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
30
- end
31
- end
32
-
33
- def self.execute(irb_context, *opts, **kwargs, &block)
34
- command = new(irb_context)
35
- command.execute(*opts, **kwargs, &block)
36
- rescue CommandArgumentError => e
37
- puts e.message
38
- end
39
-
40
- def initialize(irb_context)
41
- @irb_context = irb_context
42
- end
43
-
44
- attr_reader :irb_context
45
-
46
- def execute(*opts)
47
- #nop
48
- end
49
- end
50
- end
51
-
52
- # :startdoc:
53
- end
3
+ # This file is just a placeholder for backward-compatibility.
4
+ # Please require 'irb' and inheirt your command from `IRB::Command::Base` instead.
@@ -5,7 +5,7 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Backtrace < DebugCommand
10
10
  def self.transform_args(args)
11
11
  args&.dump
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # nop.rb -
4
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
+ #
6
+
7
+ module IRB
8
+ # :stopdoc:
9
+
10
+ module Command
11
+ class CommandArgumentError < StandardError; end
12
+
13
+ class Base
14
+ class << self
15
+ def category(category = nil)
16
+ @category = category if category
17
+ @category
18
+ end
19
+
20
+ def description(description = nil)
21
+ @description = description if description
22
+ @description
23
+ end
24
+
25
+ def help_message(help_message = nil)
26
+ @help_message = help_message if help_message
27
+ @help_message
28
+ end
29
+
30
+ private
31
+
32
+ def string_literal?(args)
33
+ sexp = Ripper.sexp(args)
34
+ sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
35
+ end
36
+
37
+ def highlight(text)
38
+ Color.colorize(text, [:BOLD, :BLUE])
39
+ end
40
+ end
41
+
42
+ def self.execute(irb_context, *opts, **kwargs, &block)
43
+ command = new(irb_context)
44
+ command.execute(*opts, **kwargs, &block)
45
+ rescue CommandArgumentError => e
46
+ puts e.message
47
+ end
48
+
49
+ def initialize(irb_context)
50
+ @irb_context = irb_context
51
+ end
52
+
53
+ attr_reader :irb_context
54
+
55
+ def execute(*opts)
56
+ #nop
57
+ end
58
+ end
59
+
60
+ Nop = Base
61
+ end
62
+
63
+ # :startdoc:
64
+ end
@@ -5,7 +5,7 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Break < DebugCommand
10
10
  def self.transform_args(args)
11
11
  args&.dump
@@ -5,7 +5,7 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Catch < DebugCommand
10
10
  def self.transform_args(args)
11
11
  args&.dump
@@ -1,18 +1,16 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # change-ws.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
5
  #
6
-
7
- require_relative "nop"
8
6
  require_relative "../ext/change-ws"
9
7
 
10
8
  module IRB
11
9
  # :stopdoc:
12
10
 
13
- module ExtendCommand
11
+ module Command
14
12
 
15
- class CurrentWorkingWorkspace < Nop
13
+ class CurrentWorkingWorkspace < Base
16
14
  category "Workspace"
17
15
  description "Show the current workspace."
18
16
 
@@ -21,7 +19,7 @@ module IRB
21
19
  end
22
20
  end
23
21
 
24
- class ChangeWorkspace < Nop
22
+ class ChangeWorkspace < Base
25
23
  category "Workspace"
26
24
  description "Change the current workspace to an object."
27
25
 
@@ -5,7 +5,7 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Continue < DebugCommand
10
10
  def execute(*args)
11
11
  super(do_cmds: ["continue", *args].join(" "))
@@ -1,18 +1,17 @@
1
- require_relative "nop"
2
1
  require_relative "../debug"
3
2
 
4
3
  module IRB
5
4
  # :stopdoc:
6
5
 
7
- module ExtendCommand
8
- class Debug < Nop
6
+ module Command
7
+ class Debug < Base
9
8
  category "Debugging"
10
9
  description "Start the debugger of debug.gem."
11
10
 
12
11
  BINDING_IRB_FRAME_REGEXPS = [
13
12
  '<internal:prelude>',
14
13
  binding.method(:irb).source_location.first,
15
- ].map { |file| /\A#{Regexp.escape(file)}:\d+:in `irb'\z/ }
14
+ ].map { |file| /\A#{Regexp.escape(file)}:\d+:in (`|'Binding#)irb'\z/ }
16
15
 
17
16
  def execute(pre_cmds: nil, do_cmds: nil)
18
17
  if irb_context.with_debugger
@@ -5,7 +5,7 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Delete < DebugCommand
10
10
  def execute(*args)
11
11
  super(pre_cmds: ["delete", *args].join(" "))
@@ -0,0 +1,70 @@
1
+ require 'shellwords'
2
+
3
+ require_relative "../source_finder"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module Command
9
+ class Edit < Base
10
+ category "Misc"
11
+ description 'Open a file or source location.'
12
+ help_message <<~HELP_MESSAGE
13
+ Usage: edit [FILE or constant or method signature]
14
+
15
+ Open a file in the editor specified in #{highlight('ENV["VISUAL"]')} or #{highlight('ENV["EDITOR"]')}
16
+
17
+ - If no arguments are provided, IRB will attempt to open the file the current context was defined in.
18
+ - If FILE is provided, IRB will open the file.
19
+ - If a constant or method signature is provided, IRB will attempt to locate the source file and open it.
20
+
21
+ Examples:
22
+
23
+ edit
24
+ edit foo.rb
25
+ edit Foo
26
+ edit Foo#bar
27
+ HELP_MESSAGE
28
+
29
+ class << self
30
+ def transform_args(args)
31
+ # Return a string literal as is for backward compatibility
32
+ if args.nil? || args.empty? || string_literal?(args)
33
+ args
34
+ else # Otherwise, consider the input as a String for convenience
35
+ args.strip.dump
36
+ end
37
+ end
38
+ end
39
+
40
+ def execute(*args)
41
+ path = args.first
42
+
43
+ if path.nil?
44
+ path = @irb_context.irb_path
45
+ elsif !File.exist?(path)
46
+ source = SourceFinder.new(@irb_context).find_source(path)
47
+
48
+ if source&.file_exist? && !source.binary_file?
49
+ path = source.file
50
+ end
51
+ end
52
+
53
+ unless File.exist?(path)
54
+ puts "Can not find file: #{path}"
55
+ return
56
+ end
57
+
58
+ if editor = (ENV['VISUAL'] || ENV['EDITOR'])
59
+ puts "command: '#{editor}'"
60
+ puts " path: #{path}"
61
+ system(*Shellwords.split(editor), path)
62
+ else
63
+ puts "Can not find editor setting: ENV['VISUAL'] or ENV['EDITOR']"
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ # :startdoc:
70
+ end
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "nop"
4
-
5
3
  module IRB
6
4
  # :stopdoc:
7
5
 
8
- module ExtendCommand
9
- class Exit < Nop
6
+ module Command
7
+ class Exit < Base
10
8
  category "IRB"
11
9
  description "Exit the current irb session."
12
10
 
@@ -5,7 +5,7 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Finish < DebugCommand
10
10
  def execute(*args)
11
11
  super(do_cmds: ["finish", *args].join(" "))
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ # :stopdoc:
5
+
6
+ module Command
7
+ class ForceExit < Base
8
+ category "IRB"
9
+ description "Exit the current process."
10
+
11
+ def execute(*)
12
+ throw :IRB_EXIT, true
13
+ rescue UncaughtThrowError
14
+ Kernel.exit!
15
+ end
16
+ end
17
+ end
18
+
19
+ # :startdoc:
20
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Command
5
+ class Help < Base
6
+ category "Help"
7
+ description "List all available commands. Use `help <command>` to get information about a specific command."
8
+
9
+ class << self
10
+ def transform_args(args)
11
+ # Return a string literal as is for backward compatibility
12
+ if args.empty? || string_literal?(args)
13
+ args
14
+ else # Otherwise, consider the input as a String for convenience
15
+ args.strip.dump
16
+ end
17
+ end
18
+ end
19
+
20
+ def execute(command_name = nil)
21
+ content =
22
+ if command_name
23
+ if command_class = ExtendCommandBundle.load_command(command_name)
24
+ command_class.help_message || command_class.description
25
+ else
26
+ "Can't find command `#{command_name}`. Please check the command name and try again.\n\n"
27
+ end
28
+ else
29
+ help_message
30
+ end
31
+ Pager.page_content(content)
32
+ end
33
+
34
+ private
35
+
36
+ def help_message
37
+ commands_info = IRB::ExtendCommandBundle.all_commands_info
38
+ commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }
39
+
40
+ user_aliases = irb_context.instance_variable_get(:@user_aliases)
41
+
42
+ commands_grouped_by_categories["Aliases"] = user_aliases.map do |alias_name, target|
43
+ { display_name: alias_name, description: "Alias for `#{target}`" }
44
+ end
45
+
46
+ if irb_context.with_debugger
47
+ # Remove the original "Debugging" category
48
+ commands_grouped_by_categories.delete("Debugging")
49
+ # Add an empty "Debugging (from debug.gem)" category at the end
50
+ commands_grouped_by_categories["Debugging (from debug.gem)"] = []
51
+ end
52
+
53
+ longest_cmd_name_length = commands_info.map { |c| c[:display_name].length }.max
54
+
55
+ output = StringIO.new
56
+
57
+ help_cmds = commands_grouped_by_categories.delete("Help")
58
+
59
+ add_category_to_output("Help", help_cmds, output, longest_cmd_name_length)
60
+
61
+ commands_grouped_by_categories.each do |category, cmds|
62
+ add_category_to_output(category, cmds, output, longest_cmd_name_length)
63
+ end
64
+
65
+ # Append the debugger help at the end
66
+ if irb_context.with_debugger
67
+ output.puts DEBUGGER__.help
68
+ end
69
+
70
+ output.string
71
+ end
72
+
73
+ def add_category_to_output(category, cmds, output, longest_cmd_name_length)
74
+ output.puts Color.colorize(category, [:BOLD])
75
+
76
+ cmds.each do |cmd|
77
+ output.puts " #{cmd[:display_name].to_s.ljust(longest_cmd_name_length)} #{cmd[:description]}"
78
+ end
79
+
80
+ output.puts
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "stringio"
4
- require_relative "nop"
4
+
5
5
  require_relative "../pager"
6
6
 
7
7
  module IRB
8
8
  # :stopdoc:
9
9
 
10
- module ExtendCommand
11
- class History < Nop
10
+ module Command
11
+ class History < Base
12
12
  category "IRB"
13
13
  description "Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output."
14
14
 
@@ -5,7 +5,7 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Info < DebugCommand
10
10
  def self.transform_args(args)
11
11
  args&.dump
@@ -1,12 +1,10 @@
1
- # frozen_string_literal: false
2
-
3
- require_relative "nop"
1
+ # frozen_string_literal: true
4
2
 
5
3
  module IRB
6
4
  # :stopdoc:
7
5
 
8
- module ExtendCommand
9
- class IrbInfo < Nop
6
+ module Command
7
+ class IrbInfo < Base
10
8
  category "IRB"
11
9
  description "Show information about IRB."
12
10
 
@@ -15,7 +13,8 @@ module IRB
15
13
  str += "IRB version: #{IRB.version}\n"
16
14
  str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
17
15
  str += "Completion: #{IRB.CurrentContext.io.respond_to?(:completion_info) ? IRB.CurrentContext.io.completion_info : 'off'}\n"
18
- str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
16
+ rc_files = IRB.rc_files.select { |rc| File.exist?(rc) }
17
+ str += ".irbrc paths: #{rc_files.join(", ")}\n" if rc_files.any?
19
18
  str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
20
19
  str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
21
20
  str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
@@ -1,17 +1,15 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # load.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
5
  #
6
-
7
- require_relative "nop"
8
6
  require_relative "../ext/loader"
9
7
 
10
8
  module IRB
11
9
  # :stopdoc:
12
10
 
13
- module ExtendCommand
14
- class LoaderCommand < Nop
11
+ module Command
12
+ class LoaderCommand < Base
15
13
  include IrbLoader
16
14
 
17
15
  def raise_cmd_argument_error
@@ -2,17 +2,23 @@
2
2
 
3
3
  require "reline"
4
4
  require "stringio"
5
- require_relative "nop"
5
+
6
6
  require_relative "../pager"
7
7
  require_relative "../color"
8
8
 
9
9
  module IRB
10
10
  # :stopdoc:
11
11
 
12
- module ExtendCommand
13
- class Ls < Nop
12
+ module Command
13
+ class Ls < Base
14
14
  category "Context"
15
- description "Show methods, constants, and variables. `-g [query]` or `-G [query]` allows you to filter out the output."
15
+ description "Show methods, constants, and variables."
16
+
17
+ help_message <<~HELP_MESSAGE
18
+ Usage: ls [obj] [-g [query]]
19
+
20
+ -g [query] Filter the output with a query.
21
+ HELP_MESSAGE
16
22
 
17
23
  def self.transform_args(args)
18
24
  if match = args&.match(/\A(?<args>.+\s|)(-g|-G)\s+(?<grep>[^\s]+)\s*\n\z/)
@@ -1,10 +1,8 @@
1
- require_relative "nop"
2
-
3
1
  module IRB
4
2
  # :stopdoc:
5
3
 
6
- module ExtendCommand
7
- class Measure < Nop
4
+ module Command
5
+ class Measure < Base
8
6
  category "Misc"
9
7
  description "`measure` enables the mode to measure processing time. `measure :off` disables it."
10
8
 
@@ -5,7 +5,7 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Next < DebugCommand
10
10
  def execute(*args)
11
11
  super(do_cmds: ["next", *args].join(" "))
@@ -1,22 +1,37 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # change-ws.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
5
  #
6
6
 
7
- require_relative "nop"
8
7
  require_relative "../ext/workspaces"
9
8
 
10
9
  module IRB
11
10
  # :stopdoc:
12
11
 
13
- module ExtendCommand
14
- class Workspaces < Nop
12
+ module Command
13
+ class Workspaces < Base
15
14
  category "Workspace"
16
15
  description "Show workspaces."
17
16
 
18
17
  def execute(*obj)
19
- irb_context.workspaces.collect{|ws| ws.main}
18
+ inspection_resuls = irb_context.instance_variable_get(:@workspace_stack).map do |ws|
19
+ truncated_inspect(ws.main)
20
+ end
21
+
22
+ puts "[" + inspection_resuls.join(", ") + "]"
23
+ end
24
+
25
+ private
26
+
27
+ def truncated_inspect(obj)
28
+ obj_inspection = obj.inspect
29
+
30
+ if obj_inspection.size > 20
31
+ obj_inspection = obj_inspection[0, 19] + "...>"
32
+ end
33
+
34
+ obj_inspection
20
35
  end
21
36
  end
22
37