123456789_123456789_123456789_123456789_123456789_

Class: IRB::Command::Edit

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
Inherits: IRB::Command::Base
Defined in: lib/irb/command/edit.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

#execute(arg)

[ GitHub ]

  
# File 'lib/irb/command/edit.rb', line 32

def execute(arg)
  # Accept string literal for backward compatibility
  path = unwrap_string_literal(arg)

  if path.nil?
    path = @irb_context.irb_path
  elsif !File.exist?(path)
    source = SourceFinder.new(@irb_context).find_source(path)

    if source&.file_exist? && !source.binary_file?
      path = source.file
    end
  end

  unless File.exist?(path)
    puts "Can not find file: #{path}"
    return
  end

  if editor = (ENV['VISUAL'] || ENV['EDITOR'])
    puts "command: '#{editor}'"
    puts "   path: #{path}"
    system(*Shellwords.split(editor), path)
  else
    puts "Can not find editor setting: ENV['VISUAL'] or ENV['EDITOR']"
  end
end