Andrew Barringer <abarringer@bsecure.com> writes:
> I'm working on a project that has a bitmap of permissions and I need to
> find out if a user has access.
>
>
>
> Given permissions bit mask of 0001C0200F02000000000 where each bit
> represents a specific permission
>
>
>
> And a request for permissions check on bits [37, 12, 48]
>
>
>
> What's the best way to find out if user has access to all requested
> permissions?
(def check(permissions,bits)
(bits . inject(true) { | r , b |
(r and (0 != (permissions & (1 << b))))
})
end)
nil
(check 0xf0,[1,4,5,6]) -> false
(check 0xf0,[4,5,6]) -> true
--
__Pascal Bourguignon__