Skip to content

Alias whereami command #1155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

william-lawrence
Copy link

@william-lawrence william-lawrence commented Aug 18, 2025

Description

Add alias @ for whereami command.

This PR introduces the alias @ for the whereami command. The reason that I wanted to add this alias because pry/pry has the same alias, and I think that is a nice quality of life feature.

Manual testing results

Below are the manual tests results. I used the provided target.rb script, but I updated the commands for a few of the iterations.

Test file

This is the same test file as the one in CONTRIBUTING.md. I am just adding it here for context.

# target.rb
class Foo
  def first_call
    second_call(20)
  end

  def second_call(num)
    third_call_with_block do |ten|
      forth_call(num, ten)
    end
  end

  def third_call_with_block(&block)
    @ivar1 = 10; @ivar2 = 20

    yield(10)
  end

  def forth_call(num1, num2)
    num1 + num2
  end
end

Foo.new.first_call

Default test

This is a test using exactly what is provided in CONTRIBUTING.md

Input:

$ exe/rdbg -e 'b 20;; c ;; bt ;; info ;; q!' -e c target.rb

Output:

$ exe/rdbg -e 'b 20;; c ;; bt ;; info ;; q!' -e c target.rb
[1, 10] in target.rb
     1| # target.rb
=>   2| class Foo
     3|   def first_call
     4|     second_call(20)
     5|   end
     6| 
     7|   def second_call(num)
     8|     third_call_with_block do |ten|
     9|       forth_call(num, ten)
    10|     end
=>#0    <main> at target.rb:2
(rdbg:commands) b 20
#0  BP - Line  /Users/will/src/debug/target.rb:20 (call)
(rdbg:commands) c
[15, 24] in target.rb
    15| 
    16|     yield(10)
    17|   end
    18| 
    19|   def forth_call(num1, num2)
=>  20|     num1 + num2
    21|   end
    22| end
    23| 
    24| Foo.new.first_call
=>#0    Foo#forth_call(num1=20, num2=10) at target.rb:20
  #1    block {|ten=10|} in second_call at target.rb:9
  # and 4 frames (use `bt' command for all frames)

Stop by #0  BP - Line  /Users/will/src/debug/target.rb:20 (call)
(rdbg:commands) bt
=>#0    Foo#forth_call(num1=20, num2=10) at target.rb:20
  #1    block {|ten=10|} in second_call at target.rb:9
  #2    Foo#third_call_with_block(block=#<Proc:0x000000011bde7198 target.rb:8>) at target.rb:16
  #3    Foo#second_call(num=20) at target.rb:8
  #4    Foo#first_call at target.rb:4
  #5    <main> at target.rb:24
(rdbg:commands) info
%self = #<Foo:0x000000011bde73a0 @ivar1=10, @ivar2=20>
num1 = 20
num2 = 10
@ivar1 = 10
@ivar2 = 20
(rdbg:commands) q!

Test with whereami and @

This test uses the same test file, but uses an adjusted command to test whereami, @, and reading instance variables

Input:

$ exe/rdbg -e 'b 15;; c ;; bt ;; whereami ;; @ivar1;; @ ;; info ;; q!' -e c target.rb

Output:

$ exe/rdbg -e 'b 15;; c ;; bt ;; whereami ;; @ivar1;; @ ;; info ;; q!' -e c target.rb
[1, 10] in target.rb
     1| # target.rb
=>   2| class Foo
     3|   def first_call
     4|     second_call(20)
     5|   end
     6| 
     7|   def second_call(num)
     8|     third_call_with_block do |ten|
     9|       forth_call(num, ten)
    10|     end
=>#0    <main> at target.rb:2
(rdbg:commands) b 15
#0  BP - Line  /Users/will/src/debug/target.rb:16 (line)
(rdbg:commands) c
[11, 20] in target.rb
    11|   end
    12| 
    13|   def third_call_with_block(&block)
    14|     @ivar1 = 10; @ivar2 = 20
    15| 
=>  16|     yield(10)
    17|   end
    18| 
    19|   def forth_call(num1, num2)
    20|     num1 + num2
=>#0    Foo#third_call_with_block(block=#<Proc:0x000000011c497718 target.rb:8>) at target.rb:16
  #1    Foo#second_call(num=20) at target.rb:8
  # and 2 frames (use `bt' command for all frames)

Stop by #0  BP - Line  /Users/will/src/debug/target.rb:16 (line)
(rdbg:commands) bt
=>#0    Foo#third_call_with_block(block=#<Proc:0x000000011c497718 target.rb:8>) at target.rb:16
  #1    Foo#second_call(num=20) at target.rb:8
  #2    Foo#first_call at target.rb:4
  #3    <main> at target.rb:24
(rdbg:commands) whereami
[11, 20] in target.rb
    11|   end
    12| 
    13|   def third_call_with_block(&block)
    14|     @ivar1 = 10; @ivar2 = 20
    15| 
=>  16|     yield(10)
    17|   end
    18| 
    19|   def forth_call(num1, num2)
    20|     num1 + num2
=>#0    Foo#third_call_with_block(block=#<Proc:0x000000011c497718 target.rb:8>) at target.rb:16
  #1    Foo#second_call(num=20) at target.rb:8
  # and 2 frames (use `bt' command for all frames)
(rdbg:commands) @ivar1
10
(rdbg:commands) @
[11, 20] in target.rb
    11|   end
    12| 
    13|   def third_call_with_block(&block)
    14|     @ivar1 = 10; @ivar2 = 20
    15| 
=>  16|     yield(10)
    17|   end
    18| 
    19|   def forth_call(num1, num2)
    20|     num1 + num2
=>#0    Foo#third_call_with_block(block=#<Proc:0x000000011c497718 target.rb:8>) at target.rb:16
  #1    Foo#second_call(num=20) at target.rb:8
  # and 2 frames (use `bt' command for all frames)
(rdbg:commands) info
%self = #<Foo:0x000000011c4978a8 @ivar1=10, @ivar2=20>
block = #<Proc:0x000000011c497718 target.rb:8>
@ivar1 = 10
@ivar2 = 20
(rdbg:commands) q!

Let me know if I need to make any changes.

@william-lawrence william-lawrence marked this pull request as ready for review August 18, 2025 20:17
@william-lawrence william-lawrence changed the title Alias whereami command Alias whereami command Aug 18, 2025
@st0012
Copy link
Member

st0012 commented Aug 19, 2025

You can get the @ right away if you enable the integration with IRB.

@william-lawrence
Copy link
Author

Oh nice! Thanks @st0012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants