Constants
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
Instance Methods
4.0
View on GitHub
# File tmp/rubies/ruby-4.0.0/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
No documentation available
4.0
View on GitHub
# File tmp/rubies/ruby-4.0.0/lib/error_highlight/core_ext.rb, line 5
def generate_snippet
if ArgumentError === self && message =~ /\A(?:wrong number of arguments|missing keyword[s]?|unknown keyword[s]?|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
# do nothing
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
No documentation available
#
4.0
View on GitHub
# File tmp/rubies/ruby-4.0.0/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
No documentation available