Skip to content

Ruby Prepend

Janet Lu edited this page Sep 15, 2022 · 3 revisions

Prepend

Prepend is a method that is baked into ruby. Prepend allows additional functionality to be added to methods that already exists in Caseflow without having to alter the original method definition. The benefit of this is that all tracked statuses can be housed in one singular directory rather than altering already existing method definitions directly within their original file.

A good example of how this works can be seen while looking at the method docket_appeal. This method is defined within app/models/pre_docket_task.rb. Rather than changing the method definition directly within the class so that it will now notify the appellant using the Appellant Notification Module, we can simply add that functionality to it outside of the pre_docket_task class by using prepend. All it takes to do this is adding a prepend statement at the top of the pre_docket_task class. In this instance, that would look like prepend AppealDocketed. The AppealDocketed module that is being prepended houses the updated functionality of the original docket_appeal method that is defined in the pre_docket_task class. This method will have super in it so that it inherits the original functionality as well as our notification method AppellantNotification.notify_appellant(appeal, @@template_name). This allows aspects of Appellant Notification to easily be altered in one directory rather than having to hunt down the notification methods all throughout Caseflow.

Clone this wiki locally