Allow for passing -n option to whereami#1170
Open
HeyNonster wants to merge 1 commit intoruby:masterfrom
Open
Conversation
`pry`'s implementation of `whereami` allows for passing quite a few arguments:
```
whereami --help
Usage: whereami [-qn] [LINES]
Describe the current location. If you use `binding.pry` inside a method then
whereami will print out the source for that method.
If a number is passed, then LINES lines before and after the current line will be
shown instead of the method itself.
The `-q` flag can be used to suppress error messages in the case that there's
no code to show. This is used by pry in the default before_session hook to show
you when you arrive at a `binding.pry`.
The `-n` flag can be used to hide line numbers so that code can be copy/pasted
effectively.
When pry was started on an Object and there is no associated method, whereami
will instead output a brief description of the current object.
-q, --quiet Don't display anything in case of an error
-n, --no-line-numbers Do not display line numbers
-m, --method Show the complete source for the current method.
-c, --class Show the complete source for the current class or module.
-f, --file Show the complete source for the current file.
-h, --help Show this message.
```
This commit is an attempt to work toward feature parity with `pry` by
first implementing `-n` as an option to remove line numbers from the output.
In doing so, we've added a `no_lineno` kwarg to `get_src` and
`show_src`, defaulting to `CONFIG[:no_lineno]` (which was previously
hardcoded inside `get_src`).
This ensures that the default behavior remains the same but gives us
the option of removing line numbers with an argument for `whereami` and
possibly other commands in the future.
Co-authored-by: Benjamin Quorning <bquorning@zendesk.com>
HeyNonster
commented
Jan 15, 2026
| register_command 'whereami', unsafe: false do | ||
| request_tc [:show, :whereami] | ||
| # * `whereami -n` | ||
| # * Show the current frame with source code without line numbers. |
Contributor
Author
There was a problem hiding this comment.
I think the main motivation for this comes from the documentation in pry:
The
-nflag can be used to hide line numbers so that code can be copy/pasted
effectively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pry's implementation ofwhereamiallows for passing quite a few arguments:This commit is an attempt to work toward feature parity with
pryby first implementing-nas an option to remove line numbers from the output.In doing so, we've added a
no_linenokwarg toget_srcandshow_src, defaulting toCONFIG[:no_lineno](which was previously hardcoded insideget_src).This ensures that the default behavior remains the same but gives us the option of removing line numbers with an argument for
whereamiand possibly other commands in the future.Thanks for your Pull Request 🎉
Please follow these instructions to help us review it more efficiently: