Exception: Literal::TypeError
- Inherits:
-
TypeError
- Object
- TypeError
- Literal::TypeError
- Includes:
- Error
- Defined in:
- lib/literal/errors/type_error.rb
Defined Under Namespace
Classes: Context
Constant Summary collapse
- INDENT =
" "
Instance Method Summary collapse
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(context:) ⇒ TypeError
constructor
A new instance of TypeError.
- #message ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(context:) ⇒ TypeError
Returns a new instance of TypeError.
46 47 48 49 50 |
# File 'lib/literal/errors/type_error.rb', line 46 def initialize(context:) @context = context super() end |
Instance Method Details
#deconstruct_keys(keys) ⇒ Object
76 77 78 |
# File 'lib/literal/errors/type_error.rb', line 76 def deconstruct_keys(keys) to_h.slice(*keys) end |
#message ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/literal/errors/type_error.rb', line 52 def = +"Type mismatch\n\n" @context.descend do |c, level| idt = INDENT * level if c.receiver || c.method << idt << c.receiver.class.inspect if c.receiver << c.method if c.method << " (from #{backtrace[1]})" if level.zero? << "\n" end if c.label idt << INDENT << idt << c.label << "\n" end if c.expected && c.children.empty? << idt << " Expected: #{c.expected.inspect}\n" << idt << " Actual (#{c.actual.class}): #{c.actual.inspect}\n" end end end |
#to_h ⇒ Object
80 81 82 |
# File 'lib/literal/errors/type_error.rb', line 80 def to_h @context.to_h end |