Class: ErrorToCommunicate::Heuristic::WrongNumberOfArguments
- Inherits:
-
ErrorToCommunicate::Heuristic
- Object
- ErrorToCommunicate::Heuristic
- ErrorToCommunicate::Heuristic::WrongNumberOfArguments
- Defined in:
- lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb
Instance Attribute Summary collapse
-
#explanation ⇒ Object
Returns the value of attribute explanation.
-
#num_expected ⇒ Object
Returns the value of attribute num_expected.
-
#num_received ⇒ Object
Returns the value of attribute num_received.
Attributes inherited from ErrorToCommunicate::Heuristic
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ WrongNumberOfArguments
constructor
A new instance of WrongNumberOfArguments.
- #semantic_explanation ⇒ Object
- #semantic_info ⇒ Object
Methods inherited from ErrorToCommunicate::Heuristic
#backtrace, #classname, #message, #semantic_backtrace, #semantic_summary
Constructor Details
#initialize ⇒ WrongNumberOfArguments
Returns a new instance of WrongNumberOfArguments.
13 14 15 16 17 |
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 13 def initialize(*) super self.num_received, self.num_expected = self.class.extract_from() self.explanation = 'Wrong number of arguments' end |
Instance Attribute Details
#explanation ⇒ Object
Returns the value of attribute explanation.
11 12 13 |
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 11 def explanation @explanation end |
#num_expected ⇒ Object
Returns the value of attribute num_expected.
11 12 13 |
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 11 def num_expected @num_expected end |
#num_received ⇒ Object
Returns the value of attribute num_received.
11 12 13 |
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 11 def num_received @num_received end |
Class Method Details
.for?(einfo) ⇒ Boolean
7 8 9 |
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 7 def self.for?(einfo) extract_from einfo. end |
Instance Method Details
#semantic_explanation ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 19 def semantic_explanation [ :message, [ [:explanation, explanation], [:context, ' (given '], [:details, num_received], [:context, ', expected '], [:details, num_expected], [:context, ')'], ] ] end |
#semantic_info ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/error_to_communicate/heuristic/wrong_number_of_arguments.rb', line 31 def semantic_info if backtrace.length == 0 [:context, "Couldn\'t find anything interesting ¯\\_(ツ)_/¯\n"] elsif backtrace.length == 1 [:heuristic, [:code, { location: backtrace[0], highlight: backtrace[0].label, context: (-5..5), emphasis: :code, }]] else [:heuristic, [ [:code, { location: backtrace[0], highlight: backtrace[0].label, context: 0..5, message: "EXPECTED #{num_expected}", emphasis: :code, }], [:code, { location: backtrace[1], highlight: backtrace[0].label, context: -5..5, message: "SENT #{num_received}", emphasis: :code, }], ]] end end |