Project

General

Profile

Actions

Bug #21760

open

Ruby::Box: a couple of require-related problems

Bug #21760: Ruby::Box: a couple of require-related problems

Added by zverok (Victor Shepelev) about 3 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
4.0.0dev (2025-12-03T05:16:03Z master 4762f429f4) +PRISM [x86_64-linux]
[ruby-core:123992]

Description

I am not sure whether all the problems have the same nature, but putting them together for now.

1. Enabling box breaks gem+require

Minimal reproducible example:

test.rb:

gem 'faraday', '= 2.14.0'
require 'faraday'
p Faraday::VERSION

(Note that there is no explicit use of Ruby::Box)

Running it with and without RUBY_BOX:

$ ruby test.rb
"2.14.0"

$ RUBY_BOX=1 ruby test.rb 
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See doc/box.md for known issues, etc.
test.rb:2:in 'Kernel#require': cannot load such file -- faraday (LoadError)
	from test.rb:2:in 'Ruby::Box::Loader#require'
	from test.rb:2:in '<main>'
test.rb:2:in 'Kernel#require': cannot load such file -- faraday (LoadError)
	from test.rb:2:in 'Ruby::Box::Loader#require'
	from test.rb:2:in '<main>'

(sic, the error is printed twice)

2. requiring the same gem from Box-loaded file and the main file

box.rb:

require 'faraday'
p "In a box: #{Faraday::VERSION}"

main.rb

b = Ruby::Box.new

b.load('box.rb')

require 'faraday'
$ RUBY_BOX=1 ruby main.rb
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See doc/box.md for known issues, etc.
"In a box: 2.14.0"
main.rb:5:in 'Kernel#require': cannot load such file -- faraday (LoadError)
	from main.rb:5:in 'Ruby::Box::Loader#require'
	from main.rb:5:in '<main>'
main.rb:5:in 'Kernel#require': cannot load such file -- faraday (LoadError)
	from main.rb:5:in 'Ruby::Box::Loader#require'
	from main.rb:5:in '<main>'

3. Box#require seem to not be aware of gems

In the example above, we see that Box-loaded file can require a gem.

This also works:

b = Ruby::Box.new

b.eval(<<~RUBY)
  require "faraday"

  p Faraday::VERSION
RUBY

(prints "2.14.0" as expected)

But this doesn't:

b = Ruby::Box.new

b.require('faraday')
$ RUBY_BOX=1 ruby test.rb 
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See doc/language/box.md for known issues, etc.
test.rb:3:in 'Ruby::Box#require': cannot load such file -- faraday (LoadError)
	from test.rb:3:in '<main>'

No data to display

Actions

Also available in: PDF Atom