20 Oct 2009

||= vs &&=

name ||= ' hello world '

name &&= name.strip

puts name == 'hello world' #=> true

In the above case I could have used strip! but I just wanted to show a contrived usage of &&= .

I see ||= all the time but I rarely see &&= .