Exception: Empirical::TypeError

Inherits:
TypeError
  • Object
show all
Defined in:
lib/empirical/type_error.rb

Class Method Summary collapse

Class Method Details

.argument_type_error(name:, value:, expected:, method_name:, context:) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/empirical/type_error.rb', line 2

def self.argument_type_error(name:, value:, expected:, method_name:, context:)
	owner = context.method(method_name).owner
	sign = owner.singleton_class? ? "." : "#"

	new(<<~MESSAGE)
		Method #{method_name} called with the wrong type for the argument #{name}.

		  #{owner.name}#{sign}#{method_name}
		    #{name}:
		      Expected: #{expected.inspect}
		      Actual (#{value.class}): #{value.inspect}
	MESSAGE
end

.return_type_error(value:, expected:, method_name:, context:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/empirical/type_error.rb', line 16

def self.return_type_error(value:, expected:, method_name:, context:)
	owner = context.method(method_name).owner
	sign = owner.singleton_class? ? "." : "#"

	new(<<~MESSAGE)
		Method #{method_name} returned the wrong type.

		  #{owner.name}#{sign}#{method_name}
		    Expected: #{expected.inspect}
		    Actual (#{value.class}): #{value.inspect}
	MESSAGE
end