How to choose between Commands and Helper Methods in IRB
masterWhen extending IRB, you must decide whether to implement a Command or a Helper Method.
Use a Command if:
- The operation is a utility performing non-Ruby related tasks (e.g.,
edit). - The operation displays information (e.g.,
show_source). - The operation requires non-Ruby syntax arguments (e.g.,
ls -g patternor flags like--flag). - Commands are generally safer as they can handle a wider variety of inputs that might not be valid Ruby code.
Use a Helper Method if:
- The operation is meant to return a Ruby object that interacts with the application.
- You want the user to be able to chain methods (e.g.,
my_helper(arg).foo). - You are providing shortcuts for frequently used Ruby operations or data structures.