From: Harold Hausman Date: 2006-08-28T22:28:53+09:00 Subject: Re: Newbie : assign a value to a variable... On 8/28/06, Nicolas Blanco wrote: > Hi all! > > This is really a newbie question... > > Here is the simple code... > > if @params[:per_page].nil? > per_page = 20 > else > per_page = @params[:per_page] > end > > Is there a better way to do this (put the parameter in the variable if > the parameter is not null, otherwise put 20) ? > #untested: per_page = (@params[:per_page] or 20) #The theory is that if @params[:per_page] is nil, it'll return false, and the 'or' will kick in. > Thanks... > You're welcome. > Nicolas > > -- > Posted via http://www.ruby-forum.com/. > hmmm, -Harold