From: dblack@... Date: 2006-08-28T22:48:29+09:00 Subject: Re: Newbie : assign a value to a variable... Hi -- On Mon, 28 Aug 2006, Harold Hausman wrote: > On 8/28/06, James Edward Gray II wrote: >> On Aug 28, 2006, at 8:30 AM, 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? >> >> IRb and Ruby treat this the same, but David didn't use "or" so the >> precedence is fine. ;) >> >> James Edward Gray II >> >> > > holycrap. > > Not to highjack this thread or anything, but what's the difference > between '||' and 'or' ? > > Only precedence? Or is 'or' some kind of tricky method? Only precedence, as far as I know. 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.