类 IRB::ExtendCommand::ShowSource
公共类方法
transform_args(args) 点击切换源代码
# File lib/irb/cmd/show_source.rb, line 15 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
公共实例方法
execute(str = nil) 点击切换源代码
# File lib/irb/cmd/show_source.rb, line 25 def execute(str = nil) 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
私有实例方法
bold(str) 点击切换源代码
# File lib/irb/cmd/show_source.rb, line 60 def bold(str) Color.colorize(str, [:BOLD]) end
show_source(source) 点击切换源代码
# File lib/irb/cmd/show_source.rb, line 47 def show_source(source) file_content = IRB::Color.colorize_code(File.read(source.file)) code = file_content.lines[(source.first_line - 1)...source.last_line].join content = <<~CONTENT #{bold("From")}: #{source.file}:#{source.first_line} #{code} CONTENT Pager.page_content(content) end