사용자가 일부 속성을 계산하는 함수를 지정할 수있게하고이 함수를 제네릭 클래스에 저장하려고합니다. 즉, 클래스의 각 인스턴스는 동일한 인터페이스를 갖지만 'calculate'메서드를 호출 한 결과는 사용자가 제공하는 함수에 따라 다릅니다.문자열에서 구문 분석하여 데이터베이스에 저장하십시오.
이 클래스를 직렬화하여 나중에 저장하려고합니다. 용도. 이것이 내가 생각하는 것입니다.
class LogicalCharge < Charge
attr_reader :name, :type, :formula, :threshold
def initialize(name: nil, type: nil, formula: nil, threshold: nil)
super(name: name, type: type)
@formula = formula
@threshold = threshold
end
def parse(formula: nil)
end
def calculate(dimensions: nil)
parse(formula: formula).call(dimensions) < threshold
end
여기서부터 어떻게하면 좋을까요?
사용자 제공 코드를 실행 하시겠습니까? 나쁜, 나쁜 생각 (보안 POV에서) –
다른 접근법에 대한 조언? – Tarlen