ccoa Member 331 Jun 27, 2007 #2 What do you mean by shorter? Theee lines is pretty short: Code: if variable == nil variable = 1 end Upvote 0 Downvote
ccoa Member 331 Jun 27, 2007 #4 Well, you could use the ternary operatior: variable = ((variable == nil) ? 1 : variable) But frankly, that's harder to read, harder to debug, and is less efficient. Upvote 0 Downvote
Well, you could use the ternary operatior: variable = ((variable == nil) ? 1 : variable) But frankly, that's harder to read, harder to debug, and is less efficient.
Yeyinde Sponsor 1,122 Jun 27, 2007 #5 The shortest way is this: Code: variable ||= value Upvote 0 Downvote
tibuda Member 380 Jun 27, 2007 #6 I would suggest Code: variable = 1 if variable.nil? Upvote 0 Downvote