summaryrefslogtreecommitdiff
path: root/lib/irb
diff options
context:
space:
mode:
authorStan Lo <stan.lo@shopify.com>2022-12-12 17:35:43 +0000
committergit <svn-admin@ruby-lang.org>2022-12-12 17:35:48 +0000
commit223d4448c827b9daeb6a61312777e67405e66379 (patch)
tree852479c3f432849351c09700e45bb983a6a6d52e /lib/irb
parentece624605785f6640118a0cfd97618e71abfbee8 (diff)
[ruby/irb] `show_doc` command should take non-string argument too
(https://github.com/ruby/irb/pull/478) Given that `show_doc` already supports syntax like `String#gsub`, it should be able to take it in non-string form too, like `edit` and `show_source` do. This ensures users can have a consistent syntax on argument between different commands.
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/cmd/edit.rb7
-rw-r--r--lib/irb/cmd/help.rb11
-rw-r--r--lib/irb/cmd/nop.rb7
-rw-r--r--lib/irb/cmd/show_source.rb5
4 files changed, 18 insertions, 12 deletions
diff --git a/lib/irb/cmd/edit.rb b/lib/irb/cmd/edit.rb
index 98fa07e49d..0103891cf4 100644
--- a/lib/irb/cmd/edit.rb
+++ b/lib/irb/cmd/edit.rb
@@ -18,13 +18,6 @@ module IRB
args.strip.dump
end
end
-
- private
-
- def string_literal?(args)
- sexp = Ripper.sexp(args)
- sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
- end
end
def execute(*args)
diff --git a/lib/irb/cmd/help.rb b/lib/irb/cmd/help.rb
index 3ef59f5eea..2a135cdb14 100644
--- a/lib/irb/cmd/help.rb
+++ b/lib/irb/cmd/help.rb
@@ -16,6 +16,17 @@ module IRB
module ExtendCommand
class Help < Nop
+ class << self
+ def transform_args(args)
+ # Return a string literal as is for backward compatibility
+ if args.empty? || string_literal?(args)
+ args
+ else # Otherwise, consider the input as a String for convenience
+ args.strip.dump
+ end
+ end
+ end
+
category "Context"
description "Enter the mode to look up RI documents."
diff --git a/lib/irb/cmd/nop.rb b/lib/irb/cmd/nop.rb
index 32074f2d9f..c616c054a8 100644
--- a/lib/irb/cmd/nop.rb
+++ b/lib/irb/cmd/nop.rb
@@ -26,6 +26,13 @@ module IRB
@description = description if description
@description
end
+
+ private
+
+ def string_literal?(args)
+ sexp = Ripper.sexp(args)
+ sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
+ end
end
if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.7.0"
diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb
index b68aa257c2..ea700be4bf 100644
--- a/lib/irb/cmd/show_source.rb
+++ b/lib/irb/cmd/show_source.rb
@@ -65,11 +65,6 @@ module IRB
end
first_line
end
-
- def string_literal?(args)
- sexp = Ripper.sexp(args)
- sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
- end
end
def execute(str = nil)