assume the following ruby code:
bank.branches do |branch|
branch.employees.each do |employee|
NEXT BRANCH if employee.name = \"John Doe\"
end
end
My impulse would be to move the nested blocks into a method, with a return in place of the break.
def find_branch_and_employee_by_name(bank,emp_name)
bank.branches.each do |branch|
branch.employees.each do |employee|
return([branch,employee]) if employee.name == emp_name
end
end
nil # employee wasn't found
end