Sha256: 8911435ec20e8095ae2ad45d533ea1870d2f6c5954a68812fe1f33c9ec307b9d

Contents?: true

Size: 605 Bytes

Versions: 2

Compression:

Stored size: 605 Bytes

Contents

module DidYouMean
  module Correctable
    prepend_features NameError

    def original_message
      method(:to_s).super_method.call
    end

    def to_s
      msg = super.dup
      bt  = caller(1, 6)

      if IGNORED_CALLERS.all? {|ignored| bt.grep(ignored).empty? } && (!cause.respond_to?(:corrections) || cause.corrections.empty?)
        msg << Formatter.new(corrections).to_s
      end

      msg
    rescue
      super
    end

    def corrections
      spell_checker.corrections
    end

    def spell_checker
      @spell_checker ||= SPELL_CHECKERS[self.class.to_s].new(self)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
did_you_mean-1.0.3 lib/did_you_mean/core_ext/name_error.rb
did_you_mean-1.1.2 lib/did_you_mean/core_ext/name_error.rb