Harold Hausman
8/28/2006 1:45:00 PM
On 8/28/06, James Edward Gray II <james@grayproductions.net> 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?
At least we both gave him working code, I guess... haha.
-Harold