Sha256: 3f6ce444722963d4198ff3bb55a08fbf3eccc88191c78a58a548b8993a48287c

Contents?: true

Size: 980 Bytes

Versions: 4

Compression:

Stored size: 980 Bytes

Contents

module DidYouMean
  class SimilarMethodFinder
    include BaseFinder
    attr_reader :method_name, :receiver

    def initialize(exception)
      @method_name, @receiver = exception.name, exception.receiver
    end

    def words
      method_names = receiver.methods + receiver.singleton_methods
      method_names.delete(@method_name)
      method_names.uniq
    end

    alias target_word method_name

    def format(word)
      "#{separator}#{word}"
    end

    def class_method?
      receiver.is_a? Class
    end

    def separator
      class_method? ? "." : "#"
    end
  end

  if defined?(RUBY_ENGINE)
    finders["NoMethodError"] = SimilarMethodFinder

    case RUBY_ENGINE
    when 'ruby'
      require 'did_you_mean/method_missing'
    when 'jruby'
      require 'did_you_mean/receiver_capturer'
      org.yukinishijima.ReceiverCapturer.setup(JRuby.runtime)
      NoMethodError.send(:attr, :receiver)
    else
      finders.delete("NoMethodError")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
did_you_mean-0.9.8 lib/did_you_mean/finders/similar_method_finder.rb
did_you_mean-0.9.7 lib/did_you_mean/finders/similar_method_finder.rb
did_you_mean-0.9.6-java lib/did_you_mean/finders/similar_method_finder.rb
did_you_mean-0.9.6 lib/did_you_mean/finders/similar_method_finder.rb