From: Summercool Date: 2007-09-11T08:30:08+09:00 Subject: is there a one liner to initialize a variable to 1, or increment by 1? as we can use foo ||= Cart.new so that if foo is nil, then now foo = Cart.new but let's say if I have a variable i want to increment by 1 is there an idiomatic and elegant way to say foo += 1, unless foo is nil, then set it to 1 ? maybe foo = (foo == nil ? 1 : foo + 1) but it is kind of long and not readable