From: dblack@... Date: 2006-08-28T22:47:57+09:00 Subject: Re: Newbie : assign a value to a variable... Hi -- On Mon, 28 Aug 2006, Harold Hausman wrote: >> >> You can use the || (or) operator: >> >> per_page = @params[:per_page] || 20 >> >> >> David >> > > I think you've got to be careful about your precedence there... > > irb(main):001:0> foo = nil or 20 > => 20 > irb(main):002:0> foo > => nil > irb(main):003:0> foo = (nil or 20) > => 20 > irb(main):004:0> foo > => 20 > > Though, maybe it's just irb? No, it's just "or", which I didn't use. (Look more closely at my code :-) David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <----- http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log http://www.manning.com/black => book, Ruby for Rails http://www.rubycentral.org => Ruby Central, Inc.