Tag:

ruby中的条件链接

有没有一种在Ruby中有条件地链接方法的好方法? 我想要在function上做什么 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的方式?