Class: TypeProf::Core::Narrowing
- Inherits:
-
Object
- Object
- TypeProf::Core::Narrowing
- 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
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Instance Method Summary collapse
- #and(other) ⇒ Object
-
#initialize(map) ⇒ Narrowing
constructor
A new instance of Narrowing.
- #or(other) ⇒ Object
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
#map ⇒ Object (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 |