# module IRB::IrbLoader

Provides a few commands for loading files within an irb session.

See `ExtendCommandBundle` for more information.

### Public Instance Methods

absolute_path?(path) click to toggle source

    # File lib/irb/ext/loader.rb, line 35
    def absolute_path?(path)
      File.absolute_path?(path)
    end

irb_load(fn, priv = nil) click to toggle source

Loads the given file similarly to `Kernel#load`

    # File lib/irb/ext/loader.rb, line 27
    def irb_load(fn, priv = nil)
      path = search_file_from_ruby_path(fn)
      raise LoadError, "No such file to load -- #{fn}" unless path

      load_file(path, priv)
    end

load_file(path, priv = nil) click to toggle source

Loads the given file in the current session’s context and evaluates it.

See `Irb#suspend_input_method` for more information.

    # File lib/irb/ext/loader.rb, line 98
    def load_file(path, priv = nil)
      irb.suspend_name(path, File.basename(path)) do

        if priv
          ws = WorkSpace.new(Module.new)
        else
          ws = WorkSpace.new
        end
        irb.suspend_workspace(ws) do
          FileInputMethod.open(path) do |io|
            irb.suspend_input_method(io) do
              |back_io|
              irb.signal_status(:IN_LOAD) do
                if back_io.kind_of?(FileInputMethod)
                  irb.eval_input
                else
                  begin
                    irb.eval_input
                  rescue LoadAbort
                    print "load abort!!\n"
                  end
                end
              end
            end
          end
        end
      end
    end

source_file(path) click to toggle source

Loads a given file in the current session and displays the source lines

See `Irb#suspend_input_method` for more information.

    # File lib/irb/ext/loader.rb, line 74
    def source_file(path)
      irb.suspend_name(path, File.basename(path)) do
        FileInputMethod.open(path) do |io|
          irb.suspend_input_method(io) do
            |back_io|
            irb.signal_status(:IN_LOAD) do
              if back_io.kind_of?(FileInputMethod)
                irb.eval_input
              else
                begin
                  irb.eval_input
                rescue LoadAbort
                  print "load abort!!\n"
                end
              end
            end
          end
        end
      end
    end