Chervil is a toy Lisp interpreter written in Ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

conditional.rb 604B

12345678910111213141516171819202122232425
  1. module Chervil::AST
  2. class Conditional
  3. attr_reader :predicate
  4. attr_reader :true_branch
  5. attr_reader :false_branch
  6. def initialize(predicate, true_branch, false_branch)
  7. @predicate = predicate
  8. @true_branch = true_branch
  9. @false_branch = false_branch
  10. end
  11. def ==(other)
  12. @predicate == other.predicate && @true_branch == other.true_branch && @false_branch == other.false_branch
  13. end
  14. def evaluate(env)
  15. if @predicate.evaluate(env) == false
  16. @false_branch.evaluate(env)
  17. else
  18. @true_branch.evaluate(env)
  19. end
  20. end
  21. end
  22. end