From: William James Date: 2008-09-29T06:39:15+09:00 Subject: Re: irb: 1 & 1 => 1, not true huh? I thought 1 & 1 => true On Sep 28, 4:19 pm, 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 > > TIA, You say thanks when nobody has replied, so you are thanking nobody. You should wait till someone has replied before you thank him. Otherwise, he won't even know that you have read his post; that is very rude and inconsiderate. > Pete # bitwise 254 & 15 ==>14 # boolean 254 && 15 ==>15 Only two things are untrue: nil and false. puts "it's true" if 0 it's true ==>nil puts "it's true" if 254 & 1 it's true ==>nil puts "it's true" if 254 & 1 > 0 ==>nil