有没有一种好的方法可以在Ruby中有条件地链接方法?
我想要的功能是:
我想要的功能是:
if a && b && c
my_object.some_method_because_of_a.some_method_because_of_b.some_method_because_of_c
elsif a && b && !c
my_object.some_method_because_of_a.some_method_because_of_b
elsif a && !b && c
my_object.some_method_because_of_a.some_method_because_of_c
etc...
根据多种条件,我想确定在方法链中调用哪些方法。
到目前为止,我最好的尝试是有条件地构建方法字符串,并使用 eval
,但肯定有更好的、更符合 Ruby 风格的方法吧?