Project

General

Profile

Feature #18296

Updated by Eregon (Benoit Daloze) about 3 years ago

After discussing with @eregon, we came to the conclusion that the current implementation of `did_you_mean` and `error_highlight` could avoid many issues by using `Exception#full_message`. 

 We propose to introduce a more nuanced interface: 

 ```ruby 
 class Exception 
   def full_message(highlight: bool, order: [:top or :bottom], **options) 
     # ... 
   end 
 end 

 module DidYouMean 
   module class Formatter 
     def full_message(highlight:, did_you_mean: true, **options) 
       buffer = super(highlight: highlight, **options).dup 
       buffer << "extra stuff" 
     end 
   end 
 end 
 Exception.prepend DidYouMean::Formatter 

 module ErrorHighlight 
   module class Formatter 
     def full_message(highlight:, error_highlight: true, **options) 
       # same as above 
     end 
   end 
 end 
 ErrorHighlight.prepend DidYouMean::Formatter 
 ```

Back