Christian Mayer's Weblog

Set A Default Value For A Ruby Variable

Sometimes you see something like this in Ruby source code:

var1 ||= 123

Which is a pretty awesome way to express this:

var1 = var1 || 123

What in turn means:

var1 = 123 if !var1

Or the long version:

if !var1
  var1 = 123

And in the case you only speak PHP:

    $var1 = 123;

Posted on .
Categories: Programming
Tags: Ruby, Default

Categories | RSS Feed | Usage | Imprint
Copyright © 2006 by