Class: TypeProf::Core::Narrowing

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/core/env/narrowing.rb

Defined Under Namespace

Classes: AndConstraint, Constraint, IsAConstraint, NilConstraint, OrConstraint

Constant Summary collapse

EmptyNarrowings =
[Narrowing.new({}), Narrowing.new({})]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ Narrowing

Returns a new instance of Narrowing.



3
4
5
6
# File 'lib/typeprof/core/env/narrowing.rb', line 3

def initialize(map)
  raise unless map.is_a?(Hash)
  @map = map
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



8
9
10
# File 'lib/typeprof/core/env/narrowing.rb', line 8

def map
  @map
end

Instance Method Details

#and(other) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/typeprof/core/env/narrowing.rb', line 10

def and(other)
  new_map = @map.dup
  other.map.each do |var, constraint|
    new_map[var] = new_map[var] ? new_map[var].and(constraint) : constraint
  end
  Narrowing.new(new_map)
end

#or(other) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/typeprof/core/env/narrowing.rb', line 18

def or(other)
  new_map = {}
  @map.each do |var, constraint|
    new_map[var] = constraint.or(other.map[var]) if other.map[var]
  end
  Narrowing.new(new_map)
end