Refactoring if elsif else or in Ruby block -
def main_method new_array = [] some_array.each |foo| if (method_01? foo) || (method_02? foo) || (method_03? foo) || (method_04? foo) || (method_05? foo) else new_array << foo end end end
is there better way write above code without or (||) , without elsif conditions?
is looping thru hash appropriate such refactoring?
maybe help?
i've updated answer splitting array on 2 groups.
def main_method methods = [:method1, :method2, :method3] non_passed_elems, passed_elems = some_array.partition |elem| methods.none? |method| send(method, elem) end end passed_elems.each{ |t| method_for_passed_elems(t) } non_passed_elems.each{ |t| method_for_non_passed_elems(t) } end
Comments
Post a Comment