From: Charles Oliver Nutter Date: 2008-09-29T06:32:01+09:00 Subject: Re: irb: 1 & 1 => 1, not true huh? I thought 1 & 1 => true Peter Alvin wrote: > In irb I did: > > puts 1 & 1 > and get 1 > shouldn't I get true? > > Bottom line is this: What is Ruby idiom to test for bit mask? Is there > a more simple way to write: > > if session[:permissions] & Permissions::SomeMask == > Permissions::SomeMask > # user has permission to wash clothes, etc. > end a && b returns the first false element or the last true element. a & b where a and b are Fixnums does a bit mask like you're looking for. - Charlie