class So::Exists
Public Class Methods
new(variable, expr)
click to toggle source
# File lib/spec_object.rb, line 286 def initialize(variable, expr) raise "expected variable" unless variable.is_a?(Variable) @variable = variable @expr = expr.to_so_expr end
Public Instance Methods
evaluate(calls)
click to toggle source
# File lib/spec_object.rb, line 302 def evaluate(calls) if @variable.time? posibilities = (0...calls.size).map do |t| v = @expr.substitute(@variable, Time.new(t)).evaluate(calls) end t = posibilities.any? do |v| v.kind_of?(Const) && v.value end if t true.to_so_expr else f = posibilities.all? do |v| v.kind_of?(Const) && !(v.value) end if f false.to_so_expr else self end end elsif @variable.value? self else raise "cannot infer the type of #{@variable.pp(0)}" end end
pp(n)
click to toggle source
# File lib/spec_object.rb, line 293 def pp(n) "#{' '*n}(exists #{@variable.pp(0)}\n#{@expr.pp(n+2)})" end
substitute(v, e)
click to toggle source
# File lib/spec_object.rb, line 297 def substitute(v, e) raise "bad thing happ(n)ened" if v.object_id == @variable.object_id Exists.new(@variable, @expr.substitute(v, e)) end