Skip to content

Commit ddda23f

Browse files
committed
Reach the Irb through Context#irb in commands again
Context#irb is always the Irb running the command, so injecting it separately added an API without changing behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175QjMQGeUPByLSqoL6ye5U
1 parent eb86113 commit ddda23f

5 files changed

Lines changed: 8 additions & 16 deletions

File tree

‎lib/irb.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def evaluate_statement(statement, line_no) # :nodoc:
248248
result = @context.evaluate_expression(statement.code, line_no)
249249
@context.set_last_value(result)
250250
when Statement::Command
251-
statement.command_class.execute(@context, statement.arg, irb: self)
251+
statement.command_class.execute(@context, statement.arg)
252252
when Statement::IncorrectAlias
253253
warn statement.message
254254
end

‎lib/irb/command/base.rb‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def help_message(help_message = nil)
3131
@help_message
3232
end
3333

34-
def execute(irb_context, arg, irb: nil)
35-
new(irb_context, irb: irb).execute(arg)
34+
def execute(irb_context, arg)
35+
new(irb_context).execute(arg)
3636
rescue CommandArgumentError => e
3737
puts e.message
3838
end
@@ -79,19 +79,12 @@ def wrap_lines(text, width)
7979
end
8080
end
8181

82-
def initialize(irb_context, irb: nil)
82+
def initialize(irb_context)
8383
@irb_context = irb_context
84-
@irb = irb
8584
end
8685

8786
attr_reader :irb_context
8887

89-
# The Irb running this command. Falls back to Context#irb for commands
90-
# executed outside of Irb's loop.
91-
def irb
92-
@irb || irb_context.irb
93-
end
94-
9588
def execute(arg)
9689
#nop
9790
end

‎lib/irb/command/debug.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def execute_debug_command(pre_cmds: nil, do_cmds: nil)
4141
return
4242
end
4343

44-
unless IRB::Debug.setup(irb)
44+
unless IRB::Debug.setup(irb_context.irb)
4545
puts <<~MSG
4646
You need to install the debug gem before using this command.
4747
If you use `bundle exec`, please add `gem "debug"` into your Gemfile.

‎lib/irb/context.rb‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,7 @@ def main
251251
# context is created. See ::new for more # information on +input_method+.
252252
attr_accessor :io
253253

254-
# The Irb that owns this context.
255-
#
256-
# Prefer not to depend on this: commands get the Irb running them through
257-
# Command::Base#irb.
254+
# Current irb session.
258255
attr_accessor :irb
259256
# A copy of the default <code>IRB.conf[:AP_NAME]</code>
260257
attr_accessor :ap_name

‎lib/irb/ext/loader.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def search_file_from_ruby_path(fn) # :nodoc:
3939
#
4040
# See Irb#suspend_input_method for more information.
4141
def source_file(path)
42+
irb = irb_context.irb
4243
irb.suspend_name(path, File.basename(path)) do
4344
FileInputMethod.open(path) do |io|
4445
irb.suspend_input_method(io) do
@@ -63,6 +64,7 @@ def source_file(path)
6364
#
6465
# See Irb#suspend_input_method for more information.
6566
def load_file(path, priv = nil)
67+
irb = irb_context.irb
6668
irb.suspend_name(path, File.basename(path)) do
6769

6870
if priv

0 commit comments

Comments
 (0)