What does the fail keyword do in Ruby?

前端 未结 4 1291
南旧
南旧 2020-12-13 16:52

I am learning Ruby and encountered the fail keyword. What does it mean?

if password.length < 8
   fail \"Password too short\"
end
unless  use         


        
4条回答
  •  無奈伤痛
    2020-12-13 17:30

    Rubocop says about usage of both words;

    'Use fail instead of raise to signal exceptions.'

    'Use raise instead of fail to rethrow exceptions.'

    Here is an example.

    def sample
      fail 'something wrong' unless success?
    rescue => e
      logger.error e
      raise
    end
    

提交回复
热议问题