aforalegria
aforalegria

Reputation: 370

One line if statement in Ruby

I have following piece of code:

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

Can I write it in one line different than:

if day > 31 then day -= 31 and month = "April" end

?

I've tried it like:

if day > 31 {day -= 31; month = "April"} 

But it doesn't work

Upvotes: 1

Views: 4966

Answers (1)

shivam
shivam

Reputation: 16506

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

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

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

Upvotes: 9

Related Questions