Skip to content

Commit 507ae0b

Browse files
committed
refactor: rename reload command to box_reload and mark as experimental
1 parent df9d6d7 commit 507ae0b

3 files changed

Lines changed: 39 additions & 14 deletions

File tree

lib/irb/command/reload.rb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,42 @@ module IRB
44
# :stopdoc:
55

66
module Command
7-
class Reload < Base
7+
class BoxReload < Base
88
category "IRB"
9-
description "Reload files that were loaded via require in IRB session."
9+
description "[Experimental] Reload files that were loaded via require in IRB session (requires Ruby::Box)."
10+
11+
help_message <<~HELP
12+
Usage: box_reload
13+
14+
Reloads all Ruby files that were loaded via `require` or `require_relative`
15+
during the current IRB session. This allows you to pick up changes made to
16+
source files without restarting IRB.
17+
18+
Setup:
19+
1. Start Ruby with RUBY_BOX=1 environment variable
20+
2. Set IRB.conf[:RELOADABLE_REQUIRE] = true in your .irbrc
21+
22+
Example:
23+
# In .irbrc:
24+
IRB.conf[:RELOADABLE_REQUIRE] = true
25+
26+
# In IRB session:
27+
require 'my_lib' # loaded and tracked
28+
# ... edit my_lib.rb ...
29+
box_reload # reloads the file
30+
31+
Note: This feature is experimental and requires Ruby::Box (Ruby 4.0+).
32+
Native extensions (.so/.bundle) cannot be reloaded.
33+
HELP
1034

1135
def execute(_arg)
1236
unless reloadable_require_available?
13-
warn "The reload command requires IRB.conf[:RELOADABLE_REQUIRE] = true and Ruby::Box (Ruby 4.0+) with RUBY_BOX=1 environment variable."
37+
warn "box_reload requires IRB.conf[:RELOADABLE_REQUIRE] = true and Ruby::Box (Ruby 4.0+) with RUBY_BOX=1 environment variable."
1438
return
1539
end
1640

17-
files = IRB.conf[:__RELOADABLE_FILES__]
41+
ReloadableRequire.collect_autoloaded_files
42+
files = ReloadableRequire.reloadable_files
1843
if files.empty?
1944
puts "No files to reload. Use require to load files first."
2045
return

lib/irb/default_commands.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def load_command(command)
253253

254254
register(:cd, Command::CD)
255255
register(:copy, Command::Copy)
256-
register(:reload, Command::Reload)
256+
register(:box_reload, Command::BoxReload)
257257
end
258258

259259
ExtendCommand = Command

test/irb/test_reloadable_require.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_require_enables_reload
3737
type "require 'nested_a'"
3838
type "NESTED_A_VALUE"
3939
type "NESTED_B_VALUE"
40-
type "reload"
40+
type "box_reload"
4141
type "exit!"
4242
end
4343

@@ -56,7 +56,7 @@ def test_require_relative_from_irb_prompt_enables_reload
5656
type "require_relative 'require_relative_lib'"
5757
type "REQUIRE_RELATIVE_LIB_VALUE"
5858
type "REQUIRE_RELATIVE_DEP"
59-
type "reload"
59+
type "box_reload"
6060
type "exit!"
6161
end
6262

@@ -75,7 +75,7 @@ def test_require_with_nested_require_relative_enables_reload
7575
type "require '#{@relative_nested_a_path}'"
7676
type "RELATIVE_NESTED_A"
7777
type "RELATIVE_NESTED_B"
78-
type "reload"
78+
type "box_reload"
7979
type "exit!"
8080
end
8181

@@ -94,7 +94,7 @@ def test_autoload_enables_reload
9494
type "autoload :AutoloadMain, 'autoload_main'"
9595
type "AutoloadMain::VALUE"
9696
type "AUTOLOAD_DEP_VALUE"
97-
type "reload"
97+
type "box_reload"
9898
type "exit!"
9999
end
100100

@@ -110,7 +110,7 @@ def test_reload_without_any_loaded_files
110110
RUBY
111111

112112
output = run_ruby_file do
113-
type "reload"
113+
type "box_reload"
114114
type "exit!"
115115
end
116116

@@ -126,7 +126,7 @@ def test_reload_reflects_file_changes
126126
type "require '#{@changeable_lib_path}'"
127127
type "CHANGEABLE_VALUE"
128128
type "File.write('#{@changeable_lib_path}', \"CHANGEABLE_VALUE = 'modified'\\n\")"
129-
type "reload"
129+
type "box_reload"
130130
type "CHANGEABLE_VALUE"
131131
type "exit!"
132132
end
@@ -146,7 +146,7 @@ def test_reload_command_without_reloadable_require_enabled
146146
RUBY
147147

148148
output = run_ruby_file do
149-
type "reload"
149+
type "box_reload"
150150
type "exit!"
151151
end
152152

@@ -194,7 +194,7 @@ def test_reload_preserves_loaded_features
194194
output = run_ruby_file do
195195
type "require 'nested_a'"
196196
type "$LOADED_FEATURES.include?('#{@nested_a_path}')"
197-
type "reload"
197+
type "box_reload"
198198
type "$LOADED_FEATURES.include?('#{@nested_a_path}')"
199199
type "exit!"
200200
end
@@ -363,7 +363,7 @@ def test_reload_command_shows_error_without_ruby_box
363363
RUBY
364364

365365
output = run_ruby_file do
366-
type "reload"
366+
type "box_reload"
367367
type "exit!"
368368
end
369369

0 commit comments

Comments
 (0)