File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module IRB
4+ # :stopdoc:
5+
6+ module Command
7+ class Reload < Base
8+ category "IRB"
9+ description "Reload files that were loaded via require in IRB session."
10+
11+ def execute ( _arg )
12+ 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."
14+ return
15+ end
16+
17+ files = IRB . conf [ :__RELOADABLE_FILES__ ]
18+ if files . empty?
19+ puts "No files to reload. Use require to load files first."
20+ return
21+ end
22+
23+ files . each { |path | reload_file ( path ) }
24+ end
25+
26+ private
27+
28+ def reloadable_require_available?
29+ IRB . conf [ :RELOADABLE_REQUIRE ] && defined? ( Ruby ::Box ) && Ruby ::Box . enabled?
30+ end
31+
32+ def reload_file ( path )
33+ load path
34+ puts "Reloaded: #{ path } "
35+ rescue LoadError => e
36+ warn "Failed to reload #{ path } : #{ e . message } "
37+ rescue SyntaxError => e
38+ warn "Syntax error in #{ path } : #{ e . message } "
39+ end
40+ end
41+ end
42+
43+ # :startdoc:
44+ end
Original file line number Diff line number Diff line change 2626require_relative "command/measure"
2727require_relative "command/next"
2828require_relative "command/pushws"
29+ require_relative "command/reload"
2930require_relative "command/show_doc"
3031require_relative "command/show_source"
3132require_relative "command/step"
@@ -252,6 +253,7 @@ def load_command(command)
252253
253254 register ( :cd , Command ::CD )
254255 register ( :copy , Command ::Copy )
256+ register ( :reload , Command ::Reload )
255257 end
256258
257259 ExtendCommand = Command
You can’t perform that action at this time.
0 commit comments