Reputation: 93
Is it possible to factorize this line with a ruby operator like ||= or something else ? :
if sheet.rows[start[:y]] then row = sheet.rows[start[:y]] else row = sheet.add_row [] end
Upvotes: 0
Views: 69
Reputation: 16506
You can use ternary operator:
row = sheet.rows[start[:y]] ? sheet.rows[start[:y]] : sheet.add_row([])
Alternatively:
row = sheet.rows[start[:y]]
row = sheet.add_row [] if !row
Or (thanks to @tight):
row = sheet.rows[start[:y]] || sheet.add_row([])
Upvotes: 2