ruby / ruby/irb

After entering `debug`, _ (underscore) stops working

Open
#891 1 comment 0 reactions 1 assignee View on GitHub

@st0012 is already working on this.

Since Dec 11, 2024.

bug
Dominant language
Ruby
Stars
478
Forks
158
Avg merge
1d 12h
Merged PRs (30d)
12

Description

Description

Underscore stops working correctly after entering debug mode. Issue is present on Ruby 2.7.8-3.3.0. Cross filed from https://github.com/ruby/debug/issues/1069

Additional context

Shell session:

irb(#<RuboCop::Formatter::Markdow...):001> 3+3
=> 6
irb(#<RuboCop::Formatter::Markdow...):002> _
=> 6
irb(#<RuboCop::Formatter::Markdow...):003> debug
irb:rdbg(#<RuboCop::Formatter::Markdow...):002> 3+3
6
irb:rdbg(#<RuboCop::Formatter::Markdow...):003> _
nil

This older more detailed shell session shows that the most recent irb error seems to be returned if it were the last command.

Older Shell session:

irb(#<Foobar:0x000000011efeb9f0>):001> 3+3
=> 6

irb(#<Foobar:0x000000011efeb9f0>):002> puts _
6
=> nil

irb(#<Foobar:0x000000011efeb9f0>):003> 4+4
=> 8

irb(#<Foobar:0x000000011efeb9f0>):004> info
(rdbg:irb) info
%self = #<Foobar:0x000000011efeb9f0 @foo="bar">
@foo = "bar"

irb:rdbg(#<Foobar:0x000000011efeb9f0>):002> puts _

nil

irb:rdbg(#<Foobar:0x000000011efeb9f0>):003> 4+4
8

irb:rdbg(#<Foobar:0x000000011efeb9f0>):004> puts _

nil
irb:rdbg(#<Foobar:0x000000011efeb9f0>):005> 4+4
8

irb:rdbg(#<Foobar:0x000000011efeb9f0>):006> info
%self = #<Foobar:0x000000011efeb9f0 @foo="bar">
_ = nil
@foo = "bar"

irb:rdbg(#<Foobar:0x000000011efeb9f0>):007> ls Bar
Traceback (most recent call last):
	24: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:212:in `block in activate'
	23: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:254:in `session_server_main'
	22: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:365:in `process_event'
	21: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:403:in `wait_command_loop'
	20: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:403:in `loop'
	19: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:404:in `block in wait_command_loop'
	18: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:444:in `wait_command'
	15: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:1981:in `intercept_trap_sigint'
	 4: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/irb_integration.rb:9:in `evaluate'
(irb):7:in `set_foo': uninitialized constant Foobar::Bar (NameError)`

irb:rdbg(#<Foobar:0x000000011efeb9f0>):008> puts _
uninitialized constant Foobar::Bar
nil

irb:rdbg(#<Foobar:0x000000011efeb9f0>):009> ls Bar
Traceback (most recent call last):
	24: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:212:in `block in activate'
	23: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:254:in `session_server_main'
	22: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:365:in `process_event'
	21: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:403:in `wait_command_loop'
	20: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:403:in `loop'
	19: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:404:in `block in wait_command_loop'
	18: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:444:in `wait_command'
	15: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/session.rb:1981:in `intercept_trap_sigint'
	 4: from /Users/joesharp/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/debug-1.9.1/lib/debug/irb_integration.rb:9:in `evaluate'
(irb):9:in `set_foo': uninitialized constant Foobar::Bar (NameError)`

irb:rdbg(#<Foobar:0x000000011efeb9f0>):010> info
%self = #<Foobar:0x000000011efeb9f0 @foo="bar">
_ = #<NameError: uninitialized constant Foobar::Bar>
@foo = "bar"

irb:rdbg(#<Foobar:0x000000011efeb9f0>):011> Bar.methods
eval error: uninitialized constant Foobar::Bar
  (rdbg)/scratch.rb:1:in `set_foo'`
nil

irb:rdbg(#<Foobar:0x000000011efeb9f0>):012> info
%self = #<Foobar:0x000000011efeb9f0 @foo="bar">
_ = nil
@foo = "bar"

irb:rdbg(#<Foobar:0x000000011efeb9f0>):013> Bar.methods
eval error: uninitialized constant Foobar::Bar
  (rdbg)/scratch.rb:1:in `set_foo'`
nil

irb:rdbg(#<Foobar:0x000000011efeb9f0>):014> puts _

nil

Result of irb_info

Please paste the result of irb_info command in IRB.

ex.)

irb:rdbg(#<RuboCop::Formatter::Markdow...):004> irb_info
Ruby version: 3.2.3
IRB version: irb 1.11.2 (2024-02-07)
InputMethod: RelineInputMethod with Reline 0.4.3
Completion: Autocomplete, RegexpCompletor
.irbrc path: /Users/joesharp/.config/irb/irbrc
RUBY_PLATFORM: arm64-darwin22
LANG env: en_US.UTF-8
East Asian Ambiguous Width: 1

Terminal Emulator

What's your terminal emulator?
iTerm2

Setting Files

Are you using ~/.irbrc and ~/.inputrc?
Only an irbrc

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.