Class: Code::Type::Or
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Code::Type
#max_arguments_of, #maybe, #min_arguments_of, #repeat, #valid_for?, #|
Constructor Details
#initialize(left, right) ⇒ Or
8
9
10
11
|
# File 'lib/code/type/or.rb', line 8
def initialize(left, right)
@left = left
@right = right
end
|
Instance Attribute Details
Returns the value of attribute left.
6
7
8
|
# File 'lib/code/type/or.rb', line 6
def left
@left
end
|
Returns the value of attribute right.
6
7
8
|
# File 'lib/code/type/or.rb', line 6
def right
@right
end
|
Instance Method Details
#max_arguments ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/code/type/or.rb', line 22
def max_arguments
left_max_arguments = max_arguments_of(left)
right_max_arguments = max_arguments_of(right)
if left_max_arguments.nil? || right_max_arguments.nil?
nil
else
[left_max_arguments, right_max_arguments].max
end
end
|
#min_arguments ⇒ Object
18
19
20
|
# File 'lib/code/type/or.rb', line 18
def min_arguments
[min_arguments_of(left), min_arguments_of(right)].min
end
|
33
34
35
|
# File 'lib/code/type/or.rb', line 33
def name
"(#{left.name} | #{right.name})"
end
|
#valid?(argument) ⇒ Boolean
13
14
15
16
|
# File 'lib/code/type/or.rb', line 13
def valid?(argument)
valid_for?(expected: left, actual: argument) ||
valid_for?(expected: right, actual: argument)
end
|