这将返回if / else块方法的关键字退出吗?

时间:2016-03-03 21:03:36

标签: ruby

我有一个看起来像这样的方法,我不确定使用这个return方法是否会退出方法或if/else块。有人可以向我解释在这种情况下会发生什么。如果我达到return的条件,它会退出并点击method_I_want_to_avoid

def buy_another_pet(owner)
  if owner.has_pets?
    if owner.pets.is_healthy?
       if owner.pets.count == 3
          # Don't buy a pet
       else
          # buy another pet
          return
       end
    end
    # =====Will my return keyword avoid the below method=====?
    method_I_want_to_avoid
  end
end

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

  

如果我达到return的条件,它会退出并点击   method_I_want_to_avoid

没有。 return退出方法,而不是if / else阻止。