Ruby Oneline Rescue

后端 未结 2 1272
遇见更好的自我
遇见更好的自我 2021-02-18 18:58

I recently learned that you can use rescue on a line of code in case something goes wrong on that line (see http://www.rubyinside.com/21-ruby-tricks-902.html Tip #2

2条回答
  •  死守一世寂寞
    2021-02-18 19:51

    Reads good! But it will hit your performance. In my experience rescue is much slower when triggered and slightly slower when it's not. In all cases the if is faster. Other thing to consider, is that exceptions shouldn't be expected and you kind of are with this code. Having a hash so deeply nested might be a good smell that a refactoring is nede

提交回复
热议问题