Skip to content

Commit dd339e6

Browse files
authored
Add a section to guide users choose between helper methods and commands (#965)
1 parent 1d627ce commit dd339e6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

EXTEND_IRB.md

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ From v1.13.0, IRB provides official APIs to extend its functionality. This featu
44
customize and enhance their users' IRB sessions by adding new commands and helper methods tailored for
55
the libraries.
66

7+
## Helper Methods vs. Commands
8+
9+
- Use a helper method if the operation is meant to return a Ruby object that interacts with the application.
10+
- For example, an `admin_user` helper method that returns `User.where(admin: true).first`, which can then be used like `login_as(admin_user)`.
11+
- Use a command if the operation fits one of the following:
12+
- A utility operation that performs non-Ruby related tasks, such as IRB's `edit` command.
13+
- Displays information, like the `show_source` command.
14+
- If the operation requires non-Ruby syntax arguments, like `ls -g pattern`.
15+
16+
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.
17+
718
## Commands
819

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

0 commit comments

Comments
 (0)