From: Robert Klemme Date: 2006-02-09T18:13:23+09:00 Subject: Re: boolean annoyance Claudio Jeker wrote: > On Thu, Feb 09, 2006 at 07:35:08AM +0900, Alexis Reigel wrote: >> When I started using ruby I had exactly the same problem as you, >> porting some c code to ruby that was checking some flags. I didn't >> get to the solution myself, as I never ever thought of 0 being true. >> But once you see the advantages of it you'll really appreciate that >> convention. >> In c you do: (flags & 0x01) >> In ruby you do: (flags & 0x01 == 0) or (flags & 0x01).nonzero? >> Or even nicer: flags[0x01] > > Does flags[0x01] work with any kind of mask. I thought that flags[3] > would return the value of bit 3 and not the value of bit 0 and 1... > and from the ruby reference Bignum#[] returns the nth bit a 0 or 1 > and so your flags[0x01] would suffer the same way as (flags & 0x01). You are correct. It should have read if flags[0] == 1 .... Kind regards robert