TRUE Box#main? FALSE For method of built-in classes/modules (including RubyGems, etc) Main Box FALSE TRUE Default box, for the main .rb script (and les loaded from the main) Optional Box FALSE FALSE The boxes created by Ruby::Box.new fi User Box
Box.new Box.new require ʻjsonʼ Root Box Root Box JSON Main Box Copy from the root box Box #3 Copy from the root box JSON Box #4 Copy from the root box ff The mutable root box makes di erence between boxes
Root Box require ʻrubygemsʼ Gem Box.new Gem Box.new Gem YAML Root Box Main Box require ʻyamlʼ Box #3 require ʻyamlʼ Box #4 Gem has states as class instance variables (e.g., @loaded_specs), and it causes inconsistencies
Box to run built-ins • Source of box copies • Should be immutable • Should NOT run any code (after main starts) • Separated mutable states • Should be loaded per-box
later) Box#master? Box#root? Box#main? Master Box Root Box TRUE FALSE FALSE TRUE FALSE The master copy of boxes FALSE For methods of built-in classes/ modules Main Box FALSE FALSE TRUE Default box, for the main .rb script (and les loaded from the main) Optional Box FALSE FALSE FALSE The boxes created by Ruby::Box.new fi User Box
Box.new Master Box Master Box require ʻjsonʼ Root Box JSON Copy from the root box Main Box Copy from the root box Box #3 Box as master-copy and to run built-ins are separated! Master box never run any code after main starts Copy from the root box Box #4 Copy from the root box
Master Box Master Box require ʻrubygemsʼ Gem Copy from the root box require ʻrubygemsʼ Gem Root Box Main Box Copy from the root box require ʻrubygemsʼ Gem Box #3 Copy from the root box Every boxes have their own RubyGems (Gems are not built-in now) require ʻrubygemsʼ Gem Box #4 Copy from the root box
#22123] Do not consume BUNDLER̲SETUP outside the main box - #18218” https://github.com/ruby/ruby/pull/18218 • “Fix gemspec evaluation under Ruby::Box - #9809” https://github.com/ruby/rubygems/pull/9809 • “Make the gem CLI work under RUBY̲BOX=1 - #9810” https://github.com/ruby/rubygems/pull/9810 • “Defer unloading box-local extension DLLs on Windows - #18509” https://github.com/ruby/ruby/pull/18509' • “Fix autoload's require dispatch under Ruby::Box - #18534” https://github.com/ruby/ruby/pull/18534 • “Fix prepend ancestry order in user boxes - #18535” https://github.com/ruby/ruby/pull/18535 • “Copy box-local extensions into a process-private directory - #18536” https://github.com/ruby/ruby/pull/18536
#22090] Resolve classes in the caller's box in Marshal.load #18544” https://github.com/ruby/ruby/pull/18544 Introduces Primitive.attr! :caller_box to run Ruby code in the master box with the caller box as its context. (This idea is still in discussion)
a funky monkey patches in tests? • Applications tests sometimes need monkey patches • to mock library behaviors, IO objects, … • Most of tests can run without box. Just some of them can t. Ruby Process Application Code Test Runner Test Case Test Case Test Case • How about running tests in boxes? • Running all tests in boxes is too expensive Monkey Patches Test Case Ruby Box ’ ’ • Run just some of them in boxes!
su x test cases in Ruby Box - #382” https://github.com/test-unit/test-unit/pull/382 Loads test code of les like *.box.rb in separated boxes! Merged, and will be released in the next test-unit version (Available with Ruby 4.1 or later) fi ffi • RSpec? Rake::TestTask?