is there a ruby one-line “return if x”?

后端 未结 4 1379
有刺的猬
有刺的猬 2021-02-06 22:08

have a ton of places I need to add

if this_flag
  return
end

can that be done on one line with ruby?

4条回答
  •  一生所求
    2021-02-06 22:39

    Ruby always returns the last thing... Why not just structure your code differently?

    def returner(test)    
      "success" if test   
    end
    

    Whatever you've done last will return. I love Ruby.

提交回复
热议问题