Class: ErrorToCommunicate::Heuristic::NoMethodError

Inherits:
ErrorToCommunicate::Heuristic show all
Defined in:
lib/error_to_communicate/heuristic/no_method_error.rb

Instance Attribute Summary

Attributes inherited from ErrorToCommunicate::Heuristic

#einfo, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ErrorToCommunicate::Heuristic

#backtrace, #classname, #explanation, #initialize, #message, #semantic_backtrace, #semantic_summary

Constructor Details

This class inherits a constructor from ErrorToCommunicate::Heuristic

Class Method Details

.for?(einfo) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/error_to_communicate/heuristic/no_method_error.rb', line 8

def self.for?(einfo)
  ( einfo.classname == 'NoMethodError' ||
    einfo.classname == 'NameError'
  ) && parse_undefined_name(einfo.message)
end

Instance Method Details

#semantic_explanationObject



30
31
32
33
34
35
36
# File 'lib/error_to_communicate/heuristic/no_method_error.rb', line 30

def semantic_explanation
  if misspelling?
    "You called the method `#{undefined_method_name}' on `#{name_of_ivar}', which is nil\nPossible misspelling of `#{closest_name}'"
  else
    super
  end
end

#semantic_infoObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/error_to_communicate/heuristic/no_method_error.rb', line 18

def semantic_info
  [:heuristic,
    [:code, {
      location:  backtrace[0],
      highlight: backtrace[0].label,
      context:   -5..5,
      message:   "#{undefined_method_name} is undefined",
      emphasis:  :code,
    }]
  ]
end

#undefined_method_nameObject



14
15
16
# File 'lib/error_to_communicate/heuristic/no_method_error.rb', line 14

def undefined_method_name
  self.class.parse_undefined_name message
end