module ErrorHighlight::CoreExt
Constants
- SKIP_TO_S_FOR_SUPER_LOOKUP
-
This is a marker to let βDidYouMean::Correctable#original_message` skip the following method definition of `to_s`. See github.com/ruby/did_you_mean/pull/152
Public Instance Methods
Source
# File lib/error_highlight/core_ext.rb, line 41 def detailed_message(highlight: false, error_highlight: true, **) return super unless error_highlight snippet = generate_snippet if highlight snippet = snippet.gsub(/.+/) { "\e[1m" + $& + "\e[m" } end super + snippet end
Calls superclass method
Source
# File lib/error_highlight/core_ext.rb, line 56 def to_s msg = super snippet = generate_snippet if snippet != "" && !msg.include?(snippet) msg + snippet else msg end end
Calls superclass method
Private Instance Methods
Source
# File lib/error_highlight/core_ext.rb, line 5 def generate_snippet if ArgumentError === self && message =~ /\A(?:wrong number of arguments|missing keyword|unknown keyword|no keywords accepted)\b/ locs = self.backtrace_locations return "" if locs.size < 2 callee_loc, caller_loc = locs callee_spot = ErrorHighlight.spot(self, backtrace_location: callee_loc, point_type: :name) caller_spot = ErrorHighlight.spot(self, backtrace_location: caller_loc, point_type: :name) if caller_spot && callee_spot && caller_loc.path == callee_loc.path && caller_loc.lineno == callee_loc.lineno && caller_spot == callee_spot callee_loc = callee_spot = nil end ret = +"\n" [["caller", caller_loc, caller_spot], ["callee", callee_loc, callee_spot]].each do |header, loc, spot| out = nil if loc out = " #{ header }: #{ loc.path }:#{ loc.lineno }" if spot _, _, snippet, highlight = ErrorHighlight.formatter.message_for(spot).lines out += "\n | #{ snippet } #{ highlight }" else out += "\n (cannot create a snippet of the method definition; use Ruby 3.5 or later)" end end ret << "\n" + out if out end ret else spot = ErrorHighlight.spot(self) return "" unless spot return ErrorHighlight.formatter.message_for(spot) end end