On Mon, Mar 12, 2007 at 07:44:49PM +0900, Robert Dober wrote: > >For this particular example, the code you are looking for is: > > > > var ||= val > Please note that > var ||= val > is not the same than > var = val unless defined? var > > Very often it is preferable of course. Indeed - it will set values when var == nil or var == false as well. However, calling a run-time 'defined?' method is usually redundant, since in almost all cases you can tell statically whether it's defined or not: if false var = 123 end puts defined? var # redundant, var is *always* defined here But in some cases you might want var = val if var.nil? (e.g. if you are dealing with a boolean variable)