Class: So::And

Inherits:
Expr show all
Defined in:
lib/spec_object.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expr

#!, #<, #==, #>, #[], #assert_time, #assert_value, #to_so_expr

Constructor Details

#initialize(*args) ⇒ And

Returns a new instance of And.



206
207
208
# File 'lib/spec_object.rb', line 206

def initialize(*args)
  @args = args
end

Class Method Details

.and_(*args) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/spec_object.rb', line 210

def self.and_(*args)
  args.map! do |arg|
    arg.to_so_expr
  end

  args1 =
    args.select do |arg|
      if arg.kind_of?(Const)
        if arg.value == false
          return arg
        elsif arg.value == true
          false
        else
          true
        end
      else
        true
      end
    end

  if args1.size == 1
    args1[0]
  elsif args1.size == 0
    true.to_so_expr
  else
    new(*args1)
  end
end

Instance Method Details

#evaluate(calls) ⇒ Object



248
249
250
# File 'lib/spec_object.rb', line 248

def evaluate(calls)
  And.and_(*@args.map do |arg| arg.evaluate(calls) end)
end

#pp(n) ⇒ Object



239
240
241
242
# File 'lib/spec_object.rb', line 239

def pp(n)
  s = @args.map do |arg| arg.pp(n+2) end.join("\n")
  "#{' '*n}(and\n#{s})"
end

#substitute(v, e) ⇒ Object



244
245
246
# File 'lib/spec_object.rb', line 244

def substitute(v, e)
  And.and_(*@args.map do |arg| arg.substitute(v, e) end)
end