Skip to content
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

Help users choose between helper methods and commands in the extension document #965

Merged
merged 1 commit into from
Jun 8, 2024
Merged
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
11 changes: 11 additions & 0 deletions EXTEND_IRB.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ From v1.13.0, IRB provides official APIs to extend its functionality. This featu
customize and enhance their users' IRB sessions by adding new commands and helper methods tailored for
the libraries.

## Helper Methods vs. Commands

- Use a helper method if the operation is meant to return a Ruby object that interacts with the application.
- For example, an `admin_user` helper method that returns `User.where(admin: true).first`, which can then be used like `login_as(admin_user)`.
- Use a command if the operation fits one of the following:
- A utility operation that performs non-Ruby related tasks, such as IRB's `edit` command.
- Displays information, like the `show_source` command.
- If the operation requires non-Ruby syntax arguments, like `ls -g pattern`.

If you don't know what to pick, go with commands first. Commands are generally safer as they can handle a wider variety of inputs and use cases.

## Commands

Commands are designed to complete certain tasks or display information for the user, similar to shell commands.
Expand Down
Loading