summaryrefslogtreecommitdiff
path: root/lib/irb/cmd
diff options
context:
space:
mode:
authorpaulreece <96156234+paulreece@users.noreply.github.com>2023-11-28 09:56:47 -0500
committergit <svn-admin@ruby-lang.org>2023-11-28 14:56:51 +0000
commit891ce4614a7cab6eb76429a9972b5e8c2dc02a5d (patch)
treef31c36b4be59cf7a222a77c8a21caa809474e874 /lib/irb/cmd
parent5fc71feb6ca8b62d51f9b6421cb26c9f1228be17 (diff)
[ruby/irb] This enhancement allows a user to add the -s flag if they
want to access a methods origin definition. It allows for chaining of multiple esses to further go up the classes as needed. (https://github.com/ruby/irb/pull/770) https://github.com/ruby/irb/commit/eec1329d5a
Diffstat (limited to 'lib/irb/cmd')
-rw-r--r--lib/irb/cmd/show_source.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb
index 49cab43fab..9a0364e3eb 100644
--- a/lib/irb/cmd/show_source.rb
+++ b/lib/irb/cmd/show_source.rb
@@ -27,11 +27,18 @@ module IRB
puts "Error: Expected a string but got #{str.inspect}"
return
end
-
- source = SourceFinder.new(@irb_context).find_source(str)
+ if str.include? " -s"
+ str, esses = str.split(" -")
+ s_count = esses.count("^s").zero? ? esses.size : 1
+ source = SourceFinder.new(@irb_context).find_source(str, s_count)
+ else
+ source = SourceFinder.new(@irb_context).find_source(str)
+ end
if source
show_source(source)
+ elsif s_count
+ puts "Error: Couldn't locate a super definition for #{str}"
else
puts "Error: Couldn't locate a definition for #{str}"
end