Class: Camille::Types::Intersection
- Defined in:
- lib/camille/types/intersection.rb
Defined Under Namespace
Classes: ArgumentError
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Attributes inherited from BasicType
Instance Method Summary collapse
- #check(value) ⇒ Object
-
#initialize(left, right) ⇒ Intersection
constructor
A new instance of Intersection.
- #literal ⇒ Object
Methods inherited from BasicType
&, #&, #[], [], directly_instantiable?, inherited, instance, #transform, #|, |
Constructor Details
#initialize(left, right) ⇒ Intersection
Returns a new instance of Intersection.
8 9 10 11 12 |
# File 'lib/camille/types/intersection.rb', line 8 def initialize left, right @left = Camille::Type.instance left @right = Camille::Type.instance right @fingerprint = Digest::MD5.hexdigest "#{self.class.name}#{[@left.fingerprint, @right.fingerprint].sort}" end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
6 7 8 |
# File 'lib/camille/types/intersection.rb', line 6 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
6 7 8 |
# File 'lib/camille/types/intersection.rb', line 6 def right @right end |
Instance Method Details
#check(value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/camille/types/intersection.rb', line 14 def check value left_result = @left.check value if left_result.type_error? Camille::TypeError.new( 'intersection.left' => left_result ) else right_result = @right.check left_result.value if right_result.type_error? Camille::TypeError.new( 'intersection.right' => right_result ) else Camille::Checked.new(fingerprint, right_result.value) end end end |
#literal ⇒ Object
32 33 34 |
# File 'lib/camille/types/intersection.rb', line 32 def literal "(#{@left.literal} & #{@right.literal})" end |