diff options
author | Stan Lo <stan001212@gmail.com> | 2023-12-10 04:21:41 +0000 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-12-10 04:21:46 +0000 |
commit | 130268e264f59c037eda31205c6e2223cffafbbe (patch) | |
tree | ecf6aff5fe3505d116cd99296fd23dacc5b9d6fa /lib/irb/cmd | |
parent | 04eb1b6f2630a07b3a4140e593a4973493a71b92 (diff) |
[ruby/irb] Simplify show_source's super calculation
(https://github.com/ruby/irb/pull/807)
https://github.com/ruby/irb/commit/2cccc448de
Diffstat (limited to 'lib/irb/cmd')
-rw-r--r-- | lib/irb/cmd/show_source.rb | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb index 9a0364e3eb..826cb11ed2 100644 --- a/lib/irb/cmd/show_source.rb +++ b/lib/irb/cmd/show_source.rb @@ -27,17 +27,14 @@ module IRB puts "Error: Expected a string but got #{str.inspect}" return end - 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 + + str, esses = str.split(" -") + super_level = esses ? esses.count("s") : 0 + source = SourceFinder.new(@irb_context).find_source(str, super_level) if source show_source(source) - elsif s_count + elsif super_level > 0 puts "Error: Couldn't locate a super definition for #{str}" else puts "Error: Couldn't locate a definition for #{str}" |