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.
59 60 61 62 63 |
# File 'lib/literal/errors/type_error.rb', line 59 def initialize(context:) @context = context super() end |
Instance Method Details
#deconstruct_keys(keys) ⇒ Object
89 90 91 |
# File 'lib/literal/errors/type_error.rb', line 89 def deconstruct_keys(keys) to_h.slice(*keys) end |
#message ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/literal/errors/type_error.rb', line 65 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
93 94 95 |
# File 'lib/literal/errors/type_error.rb', line 93 def to_h @context.to_h end |