Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple bitmask attribute support for ActiveRecord

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time



Transparent manipulation of bitmask attributes.


Simply declare an existing integer column as a bitmask with its possible values.

class User < ActiveRecord::Base
  bitmask :roles, :as => [:writer, :publisher, :editor] 

You can then modify the column using the declared values without resorting to manual bitmasks.

user = User.create(:name => "Bruce", :roles => [:publisher, :editor])
# => [:publisher, :editor]
user.roles << :writer
# => [:publisher, :editor, :writer]

For the moment, querying for bitmasks is left as an exercise to the reader, but here's how to grab the bitmask for a specific possible value for use in your SQL query:

bitmask = User.bitmasks[:roles][:editor]
# Use `bitmask` as needed

Modifying possible values

Once you have data using a bitmask, don't change the order of the values, remove any values, or insert any new values in the array anywhere except at the end.

Contributing and reporting issues

Please feel free to fork & contribute fixes via GitHub pull requests. The official repository for this project is

Issues can be reported at


Copyright (c) 2007-2009 Bruce Williams. See LICENSE for details.

Something went wrong with that request. Please try again.