Class: Code::Type::Or
- Inherits:
-
Code::Type
- Object
- Code::Type
- Code::Type::Or
- Defined in:
- lib/code/type/or.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
-
#initialize(left, right) ⇒ Or
constructor
A new instance of Or.
- #max_arguments ⇒ Object
- #min_arguments ⇒ Object
- #name ⇒ Object
- #valid?(argument) ⇒ Boolean
Methods inherited from Code::Type
#max_arguments_of, #min_arguments_of, #valid_for?
Constructor Details
#initialize(left, right) ⇒ Or
Returns a new instance of 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
#left ⇒ Object (readonly)
Returns the value of attribute left.
6 7 8 |
# File 'lib/code/type/or.rb', line 6 def left @left end |
#right ⇒ Object (readonly)
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 |
#name ⇒ Object
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 |