Is it good style to explicitly return in Ruby?

前端 未结 8 2177
暗喜
暗喜 2020-11-27 10:59

Coming from a Python background, where there is always a \"right way to do it\" (a \"Pythonic\" way) when it comes to style, I\'m wondering if the same exists for Ruby. I\'v

8条回答
  •  再見小時候
    2020-11-27 11:44

    Like Ben said. The fact that 'the return value of a ruby method is the return value of the last statement in the function body' causes the return keyword to be rarely used in most ruby methods.

    def some_func_which_returns_a_list( x, y, z)
      return nil if failed_some_early_check
    
    
      # function code 
    
      @list     # returns the list
    end
    

提交回复
热议问题