summaryrefslogtreecommitdiff
path: root/lib/irb/cmd/show_source.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irb/cmd/show_source.rb')
-rw-r--r--lib/irb/cmd/show_source.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb
index f8a17822df..1fcff3e897 100644
--- a/lib/irb/cmd/show_source.rb
+++ b/lib/irb/cmd/show_source.rb
@@ -9,6 +9,24 @@ module IRB
module ExtendCommand
class ShowSource < 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
+
+ private
+
+ def string_literal?(args)
+ sexp = Ripper.sexp(args)
+ sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
+ end
+ end
+
def execute(str = nil)
unless str.is_a?(String)
puts "Error: Expected a string but got #{str.inspect}"