Class: Camille::Types::Intersection

Inherits:
BasicType
  • Object
show all
Defined in:
lib/camille/types/intersection.rb

Defined Under Namespace

Classes: ArgumentError

Instance Attribute Summary collapse

Attributes inherited from BasicType

#fingerprint

Instance Method Summary collapse

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

#leftObject (readonly)

Returns the value of attribute left.



6
7
8
# File 'lib/camille/types/intersection.rb', line 6

def left
  @left
end

#rightObject (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

#literalObject



32
33
34
# File 'lib/camille/types/intersection.rb', line 32

def literal
  "(#{@left.literal} & #{@right.literal})"
end