Exception: KXI::Exceptions::InvalidTypeException

Inherits:
Exception
  • Object
show all
Defined in:
lib/kxi/exceptions/invalid_type_exception.rb

Overview

Raised when some value is of unexpected type

Instance Method Summary collapse

Constructor Details

#initialize(act, *exp) ⇒ InvalidTypeException

Instantiates the [KXI::Exceptions::InvalidTypeException] class

Parameters:

  • exp (Array<Class>)

    Expected types

  • act (Class)

    Actual type



22
23
24
25
26
27
28
29
30
# File 'lib/kxi/exceptions/invalid_type_exception.rb', line 22

def initialize(act, *exp)
	if exp.length == 1
		super("Value is of unexpected type! Expected <#{exp[0].name}> got <#{act.name}>")
	else
		super("Value is of unexpected type! Expected { #{exp.collect {|i| "<#{i}>"}.join(', ')} } got <#{act.name}>")
	end
	@exp = exp
	@act = act
end

Instance Method Details

#actualClass

Returns actual type

Returns:

  • (Class)

    Actual type



15
16
17
# File 'lib/kxi/exceptions/invalid_type_exception.rb', line 15

def actual
	@act
end

#expectedArray<Class>

Returns expected types

Returns:

  • (Array<Class>)

    Expected types



9
10
11
# File 'lib/kxi/exceptions/invalid_type_exception.rb', line 9

def expected
	@exp
end