Skip to content

Commit

Permalink
Add a section to guide users choose between helper methods and comman…
Browse files Browse the repository at this point in the history
…ds (#965)
  • Loading branch information
st0012 committed Jun 8, 2024
1 parent 1d627ce commit dd339e6
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit dd339e6

Please sign in to comment.