Class: IRB::Command::ShowSource

Inherits:
Base show all
Includes:
RubyArgsExtractor
Defined in:
lib/irb/command/show_source.rb

Instance Attribute Summary

Attributes inherited from Base

#irb_context

Instance Method Summary collapse

Methods included from RubyArgsExtractor

#ruby_args, #unwrap_string_literal

Methods inherited from Base

category, description, execute, help_message, #initialize

Constructor Details

This class inherits a constructor from IRB::Command::Base

Instance Method Details

#execute(arg) ⇒ Object

[View source]

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/irb/command/show_source.rb', line 29

def execute(arg)
  # Accept string literal for backward compatibility
  str = unwrap_string_literal(arg)
  unless str.is_a?(String)
    puts "Error: Expected a string but got #{str.inspect}"
    return
  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 super_level > 0
    puts "Error: Couldn't locate a super definition for #{str}"
  else
    puts "Error: Couldn't locate a definition for #{str}"
  end
  nil
end