Class: Rtype::Behavior::Xor
Instance Method Summary collapse
- #error_message(value) ⇒ Object
-
#initialize(*types) ⇒ Xor
constructor
A new instance of Xor.
- #valid?(value) ⇒ Boolean
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 (value) arr = @types.map { |e| Rtype::(e, value) } arr.join "\nXOR " end |
#valid?(value) ⇒ Boolean
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 |