123456789_123456789_123456789_123456789_123456789_

Class: IRB::Command::ShowSource

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
Inherits: IRB::Command::Base
Defined in: lib/irb/command/show_source.rb

Class Method Summary

Instance Attribute Summary

Base - Inherited

Instance Method Summary

Constructor Details

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

Instance Method Details

#bold(str) (private)

[ GitHub ]

  
# File 'lib/irb/command/show_source.rb', line 69

def bold(str)
  Color.colorize(str, [:BOLD])
end

#execute(arg)

[ GitHub ]

  
# 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

#show_source(source) (private)

[ GitHub ]

  
# File 'lib/irb/command/show_source.rb', line 53

def show_source(source)
  if source.binary_file?
    content = "\n#{bold('Defined in binary file')}: #{source.file}\n\n"
  else
    code = source.colorized_content || 'Source not available'
    content = <<~CONTENT

      #{bold("From")}: #{source.file}:#{source.line}

      #{code.chomp}

    CONTENT
  end
  Pager.page_content(content)
end