ruby syntactic sugar: dealing with nils

前端 未结 6 1789
天命终不由人
天命终不由人 2021-02-10 02:45

probably asked already but I couldn\'t find it.. here are 2 common situation (for me while programming rails..) that are frustrating to write in ruby:

\"a string         


        
6条回答
  •  伪装坚强ぢ
    2021-02-10 03:09

    For the first question, I think Bob's answer is good.

    For the second question,

    var = something.very.long.and.tedious.to.write.instance_eval{nil? ? something.other : self}
    

提交回复
热议问题