Eval () vs expression tree

I am developing a survey system for our clients to report data to the central office. What questions are asked, in which cases is a complex problem, and it needs to be configured without changing the code. I am thinking of the following lines:

Model

Question < ActiveRecord::Base
  attr_accessible :conditional_statement
  has_and_belongs_to_many :named_conditionals
end

NamedConditional < ActiveRecord::Base
  attr_accessible :name
  has_and_belongs_to_many :questions

  def evaluate
    # return true or false, depending on which conditional and the state of the system
  end
end

The idea is that a NamedConditionalcan perform a system state check and return a boolean value. Then these named conventions can be referenced by name conditional_statementin Question, using many NamedConditionalslogical operands. Then the thread to determine whether the question asked is asked will look something like this:

  • Find all addicted NamedCondtionals
  • Rate all addicted NamedConditionals
  • Use the value of each NamedConditionalto measure conditional_statementinQuestion

3, eval() _? : conditional_statement , Question , (), , .

(100+) , . , NamedConditional ( ). , eval() , ? ?

+3
1

, / , .

- - . / - , , N... , .

0

Source: https://habr.com/ru/post/1791256/


All Articles