Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/irb/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def initialize(*main)
end
end

@binding.local_variable_set(:_, nil)
@binding.local_variable_set(:_, nil) unless @binding.local_variable_defined?(:_)
end

# The Binding of this workspace
Expand Down
16 changes: 16 additions & 0 deletions test/irb/test_debugger_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,22 @@ def test_irb_command_can_check_local_variables
assert_include(output, '"FooBar"')
end

def test_irb_console_mode_keeps_program_defined_underscore
@envs.merge!("RUBY_DEBUG_IRB_CONSOLE" => "true")
write_ruby <<~'ruby'
_ = :mine
binding.irb
ruby

output = run_ruby_file do
type "debug"
type "_"
type "continue"
end
assert_match(/^:mine\r?$/, output)
assert_no_match(/^nil\r?$/, output)
end

def test_help_command_is_delegated_to_the_debugger
write_ruby <<~'ruby'
binding.irb
Expand Down
12 changes: 12 additions & 0 deletions test/irb/test_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ def test_code_around_binding
IRB.conf.delete(:USE_COLORIZE)
end

def test_workspace_keeps_existing_underscore
_ = :mine
IRB::WorkSpace.new(binding)
assert_equal(:mine, _)
end

def test_workspace_defines_underscore_as_nil_when_absent
workspace = IRB::WorkSpace.new(binding)
assert_equal(true, workspace.binding.local_variable_defined?(:_))
assert_nil(workspace.binding.local_variable_get(:_))
end

def test_code_around_binding_with_existing_unreadable_file
pend 'chmod cannot make file unreadable on windows' if windows?
pend 'skipped in root privilege' if Process.uid == 0
Expand Down
Loading