Setting variable with either value

Is there a better way to write this?

@a = "abc"

@a = @b if @b

This will set value @a to @b if @b already have a value since before. If
not it will use the default @a which is "abc".

···

--
Posted via http://www.ruby-forum.com/.

If I understand you, this will do that:

   @a = @b || "abc"

-Rob

Rob Biedenharn
Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
rab@GaslightSoftware.com http://GaslightSoftware.com/

···

On Oct 15, 2010, at 3:07 PM, Paul Bergstrom wrote:

Is there a better way to write this?

@a = "abc"

@a = @b if @b

This will set value @a to @b if @b already have a value since before. If
not it will use the default @a which is "abc".