One line if statement in Ruby

前端 未结 1 453
悲&欢浪女
悲&欢浪女 2021-01-24 02:31

I have following piece of code:

if day > 31 
  day -= 31 
  month = \"April\"
end

Can I write it in one line different than:



        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-24 03:05

    (day -= 31; month = "April") if day > 31
    

    Alternate way (As suggested by @mudasobwa in comments below) :

    day, month = day - 31, "April" if day > 31
    

    0 讨论(0)
提交回复
热议问题