Class: Literal::TypeError::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/literal/errors/type_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver: nil, method: nil, label: nil, expected: nil, actual: nil, parent: nil) ⇒ Context

Returns a new instance of Context.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/literal/errors/type_error.rb', line 11

def initialize(
	receiver: nil, # _Nilable(Object)
	method: nil, # _Nilable(String)
	label: nil, # _Nilable(String)
	expected: nil, # _Nilable(_Any)
	actual: nil, # _Nilable(_Any)
	parent: nil # _Nilable(Context)
)
	@receiver = receiver
	@method = method
	@label = label
	@expected = expected
	@actual = actual
	@children = []
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



9
10
11
# File 'lib/literal/errors/type_error.rb', line 9

def actual
  @actual
end

#childrenObject (readonly)

Returns the value of attribute children.



9
10
11
# File 'lib/literal/errors/type_error.rb', line 9

def children
  @children
end

#expectedObject (readonly)

Returns the value of attribute expected.



9
10
11
# File 'lib/literal/errors/type_error.rb', line 9

def expected
  @expected
end

#labelObject (readonly)

Returns the value of attribute label.



9
10
11
# File 'lib/literal/errors/type_error.rb', line 9

def label
  @label
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/literal/errors/type_error.rb', line 9

def method
  @method
end

#receiverObject (readonly)

Returns the value of attribute receiver.



9
10
11
# File 'lib/literal/errors/type_error.rb', line 9

def receiver
  @receiver
end

Instance Method Details

#add_child(expected: nil, **kwargs) ⇒ Object



39
40
41
42
43
# File 'lib/literal/errors/type_error.rb', line 39

def add_child(expected: nil, **kwargs)
	child = self.class.new(expected:, **kwargs)
	expected.record_literal_type_errors(child) if expected.respond_to?(:record_literal_type_errors)
	@children << child
end

#descend(level = 0) {|_self, level| ... } ⇒ Object

Yields:

  • (_self, level)

Yield Parameters:



27
28
29
30
31
# File 'lib/literal/errors/type_error.rb', line 27

def descend(level = 0, &blk)
	yield self, level
	@children.each { |child| child.descend(level + 1, &blk) }
	nil
end

#fill_receiver(receiver:, method:, label: nil) ⇒ Object



33
34
35
36
37
# File 'lib/literal/errors/type_error.rb', line 33

def fill_receiver(receiver:, method:, label: nil)
	@receiver = receiver
	@method = method
	@label = label
end