Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/irb/command/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ def execute_internal(file_name = nil)
case file_name
when /\.rb$/
begin
if irb_load(file_name)
$".push file_name
return true
end
irb_load(file_name)
$".push file_name
return true
rescue LoadError
end
when /\.(so|o|sl)$/
Expand Down
15 changes: 15 additions & 0 deletions test/irb/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,21 @@ def test_irb_require_skips_file_already_loaded_by_require
assert_match(/prefix_loaded/, out)
end

def test_irb_require_loads_file_with_rb_extension_once
File.write("#{@tmpdir}/irb_require_rb_ext.rb", "$irb_require_rb_ext_count += 1\n")

out, err = execute_lines(
"$LOAD_PATH.unshift '#{@tmpdir}'\n",
"$irb_require_rb_ext_count = 0\n",
"irb_require 'irb_require_rb_ext.rb'\n",
"irb_require 'irb_require_rb_ext'\n",
"$irb_require_rb_ext_count\n",
)

assert_empty(err)
assert_match(/=> 1\n\z/, out)
end

def test_irb_require_falls_back_to_kernel_require_when_not_in_load_path
code = <<~RUBY
p 'fallback_loaded'
Expand Down
Loading