Skip to content

Conversation

@HeyNonster
Copy link
Contributor

@HeyNonster HeyNonster commented Jan 15, 2026

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.

Thanks for your Pull Request 🎉

Please follow these instructions to help us review it more efficiently:

  • Add references of related issues/PRs in the description if available.
  • If you're updating the readme file, make sure you followed the instruction here.

`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>
register_command 'whereami', unsafe: false do
request_tc [:show, :whereami]
# * `whereami -n`
# * Show the current frame with source code without line numbers.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main motivation for this comes from the documentation in pry:

The -n flag can be used to hide line numbers so that code can be copy/pasted
effectively.

@HeyNonster HeyNonster marked this pull request as ready for review January 15, 2026 12:08
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.

1 participant