Class: IRB::Command::Require

Inherits:
LoaderCommand show all
Defined in:
lib/irb/command/load.rb

Instance Attribute Summary

Attributes inherited from Base

#irb_context

Instance Method Summary collapse

Methods inherited from LoaderCommand

#raise_cmd_argument_error

Methods included from IrbLoader

#irb_load, #load_file, #old, #search_file_from_ruby_path, #source_file

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



40
41
42
43
# File 'lib/irb/command/load.rb', line 40

def execute(arg)
  args, kwargs = ruby_args(arg)
  execute_internal(*args, **kwargs)
end

#execute_internal(file_name = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/irb/command/load.rb', line 45

def execute_internal(file_name = nil)
  raise_cmd_argument_error unless file_name

  rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
  return false if $".find{|f| f =~ rex}

  case file_name
  when /\.rb$/
    begin
      if irb_load(file_name)
        $".push file_name
        return true
      end
    rescue LoadError
    end
  when /\.(so|o|sl)$/
    return ruby_require(file_name)
  end

  begin
    irb_load(f = file_name + ".rb")
    $".push f
    return true
  rescue LoadError
    return ruby_require(file_name)
  end
end