Class: Rtype::Behavior::Xor

Inherits:
Base show all
Defined in:
lib/rtype/behavior/xor.rb

Instance Method Summary collapse

Methods inherited from Base

[]

Constructor Details

#initialize(*types) ⇒ Xor

Returns a new instance of Xor.



4
5
6
# File 'lib/rtype/behavior/xor.rb', line 4

def initialize(*types)
	@types = types
end

Instance Method Details

#error_message(value) ⇒ Object



15
16
17
18
# File 'lib/rtype/behavior/xor.rb', line 15

def error_message(value)
	arr = @types.map { |e| Rtype::type_error_message(e, value) }
	arr.join "\nXOR "
end

#valid?(value) ⇒ Boolean

Returns:



8
9
10
11
12
13
# File 'lib/rtype/behavior/xor.rb', line 8

def valid?(value)
	result = @types.map do |e|
		Rtype::valid? e, value
	end
	result.count(true) == 1
end