One line if statement in Ruby

前端 未结 1 452
悲&欢浪女
悲&欢浪女 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)
提交回复
热议问题